An ionic bond is produced through the transfer of one or more valence electrons, typically from a metal to a non-metal, forming a cation and an anion that are bound by attractive electrostatic forces. On a macroscopic scale, ionic compounds (such as sodium chloride) form a crystalline lattice .
The charge on the cations and anions is determined by the number of electrons required to achieve stable noble gas electronic configurations. The ionic composition is then defined by the requirement that the resulting compound be electrically neutral.
For example, to combine Mg and Br to get an ionic compound, we first note the electronic configurations of these atoms:
In order to achieve noble gas configurations, the magnesium atom needs to lose its two valence electrons, while the bromine atom requires one additional electron to fill its outer shell. Therefore, for the resulting compound to be neutral, two bromine anions must combine with one magnesium cation to form magnesium bromide MgBr2.
Note that the cation precedes the anion both in written form and in formulas. In the written form, while the cation name is generally the same as the element, the suffix of single-atom anions is changed to -ide. In addition, though any ratio of 2 bromines to 1 magnesium atom will satisfy the two requirements above, the formula for ionic compounds in typically presented as the empirical formula, or the simplest ratio of atoms involving positive integers.