Magnesium chloride is an ionic compound. It is formed by the transfer of electrons from magnesium to chlorine atoms. The magnesium atoms lose two electrons, each to become positively charged magnesium ions (Mg2+). The chlorine atoms gain two electrons each, to become negatively charged chloride ions (Cl-). The electrostatic attraction between the positively and negatively charged ions holds the compound together.