Because Na has one too many electron to be stable, while Mg has 2. once they loose those electrons, they will be come ion. loosing one electron will give the ion a 1+ charge, and loosing 2 will create a 2+ charge
1
1
11
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq