Here's why:
* Magnesium (Mg) is in Group 2 of the periodic table, meaning it has a +2 charge as an ion (Mg²⁺).
* Fluorine (F) is in Group 17 of the periodic table, meaning it has a -1 charge as an ion (F⁻).
To balance the charges and create a neutral compound, you need two fluorine ions for every magnesium ion. This gives you the formula MgF₂.