A magnesium atom and a chlorine atom form an ionic bond in the compound magnesium chloride MgCl2 . This is because magnesium, a metal, loses two electrons to achieve a stable electron configuration, while chlorine, a non-metal, gains one electron to achieve a stable electron configuration. Since there are two chlorine atoms, the magnesium atom transfers one electron to each chlorine atom, resulting in the formation of Mg2+ and two Cl- ions, which are attracted to each other due to their opposite charges.