The chemical formula for the ionic compound magnesium chloride is MgCl2.
Magnesium chloride consists of magnesium cations (Mg2+) and chloride anions (Cl–). In order to balance the positive charge of one magnesium ion, two chloride ions are needed because each chloride ion carries a negative charge. Therefore, for every one magnesium ion, there are two chloride ions, leading to the formula MgCl2.