Here's why:
* Magnesium is a metal in Group 2 of the periodic table, meaning it has a +2 charge when it forms ions (Mg²⁺).
* Chlorine is a nonmetal in Group 17 of the periodic table, meaning it has a -1 charge when it forms ions (Cl⁻).
To balance the charges and form a neutral compound, you need two chlorine ions (2 x -1 = -2) to balance the +2 charge of the magnesium ion. This results in the formula MgCl₂.