Like all alkaline earth metals, magnesium has two valence electrons, meaning there are two electrons in its outer shell. The valence electrons are the ones that an atom shares, gains or loses when interacting with additional atoms.
The alkaline earth metals comprise Group IIA on the periodic table of elements. Magnesium, like the other alkaline earth metals, is more likely to lose its two electrons when reacting with other atoms, thereby forming divalent cations. This is due to the fact that the electrons do not have a strong bond with the nucleus. Magnesium also has a low level of electron affinity and low electronegativity. Magnesium has an atomic number of 12.