Why can two different elements have similar atomic masses?

Atomic mass is made of mass protons + mass neutrons (+ mass of electrons but that is minimal). So if the number of protons and neutrons is very nearly the same, then the atomic mass of the elements will be nearly the same. I hope I have interpreted your question correctly. You COULD have been talking about isotopes but I've not interpreted the question that way.

Two different elements can have similar atomic masses due to a phenomenon called isotopes. Isotopes are atoms of the same element with different numbers of neutrons in their nuclei. Since the atomic mass is the sum of protons and neutrons in an atom, two different isotopes of an element can have similar atomic masses. For example, chlorine-35 and chlorine-37 are two isotopes of chlorine, with atomic masses of 35 and 37 respectively. Despite having different numbers of neutrons, they have similar atomic masses.

Two different elements can have similar atomic masses due to a concept called isotope. Isotopes are atoms of the same element that have different numbers of neutrons in their nucleus. Neutrons are one of the three main subatomic particles that make up an atom, along with protons and electrons.

The atomic mass of an element is the weighted average mass of all the naturally occurring isotopes of that element, taking into account their relative abundance. Since isotopes have different numbers of neutrons, they have slightly different masses. The atomic mass of an element is calculated by multiplying the mass of each isotope by its relative abundance and summing them up.

As a result, two different elements with different numbers of protons and electrons can have similar atomic masses if they have isotopes with similar masses and abundances. This can occur when the difference in the number of protons and electrons is compensated for by the difference in the number of neutrons.