Here's how to determine the formula:
* Magnesium (Mg) has a +2 charge.
* Nitrogen (N) has a -3 charge.
To balance the charges, you need three magnesium ions (3 x +2 = +6) and two nitrogen ions (2 x -3 = -6). This results in the formula Mg₃N₂.