Hello, Emma,
Mg has atomic number 12, so it has 12 protons. It has an atomic mass of 24.3 amu (atomic mass units). Protons and neutrons are 1 amu each. Electrons are close to 0 amu, and are included in the mass weight calculations. It there are 12 protons, at 1 amu each, we can subtract 12 from the atomic mass of 24.3 to get 12.3. That is all due to the neutrons. Picking the closest whole number, we can say that Mg has 12 protons and 12 neutrons, for a total of 24 amu. The 0.3 is due to other Mg isotopes containing more than 12 neutrons. The table is an average of the isotopes found in nature. Electrons aren't cou nted in the mass. Since this is a 2+ cations, it means 2 of its 12 electrons have left, leaving 10 electrons.
Bob