From the periodic table, Magnesium is actually the element 12
and this belongs to Group 2. We know that an element in Group 2 has 2 valence electrons.
We can also determine this from the electron configuration of
Mg which is 1s² 2s²2p⁶ 3s² or
[Ne]3s². Since the outermost electron is 3s² therefore magnesium has 2 valence electrons.