(i) Magnesium loses two electrons to form a stable ion with a noble gas electron configuration. This results in the formation of an ion with a 2+ charge.
The formula of the magnesium ion is Mg2+.
(ii) Nitrogen gains three electrons to form a stable ion with a noble gas electron configuration. This results in the formation of an ion with a 3- charge.
The formula of the nitride ion is N3-.