Here's why:
* Magnesium (Mg) is an alkaline earth metal, meaning it has a +2 charge when it forms ions.
* Fluorine (F) is a halogen, meaning it has a -1 charge when it forms ions.
To balance the charges and form a neutral compound, two fluoride ions (2 x -1 = -2) are needed for every magnesium ion (+2). This results in the formula MgF₂.