Hey there!
Magnesium has 12 electrons.
Magnesium is in group 3, so it already has 1s, 2s, and 2p filled.
It is the second element in group 3, so 3p is the next orbital that is filled.
The superscripts are the number of electrons in the orbitals.
1s²2s²2p⁶2s²
Also, to check, add the number of electrons:
2 + 2 + 6 + 2 = 12 electrons
Hope this helps!