Here's why:
* Magnesium (Mg) is a metal in Group 2 of the periodic table, meaning it forms a +2 cation (Mg²⁺).
* Chlorine (Cl) is a nonmetal in Group 17, meaning it forms a -1 anion (Cl⁻).
To create a neutral compound, two chloride ions (2 x -1 = -2) are needed to balance the +2 charge of the magnesium ion. This results in the formula MgCl₂.