Metalatoms have only a few electrons in their outer shell whereas non-metal atoms have lots of electrons in their outer shell. This means that metals tend to react with non-metals. When a metal reacts with a non-metal, electrons transfer from the metal to the non-metal. This creates oppositely charged ions:
The strong electrostatic forces of attraction between the oppositely charged ions hold them together. A small separate molecule like water only contains three atoms. However, an ionic compound contains millions of ions, arranged in a regular 3D pattern. This arrangement is called a giant ionic lattice.
A dot and cross diagram models the transfer of electrons from metal atoms to non-metal atoms. The electrons from one atom are shown as dots, and the electrons from the other atom are shown as crosses.
When sodium reacts with chlorine, one electron is transferred from the sodium atom to the chlorine atom. This creates a positive sodium ion and a negative chloride ion.
For every sodium ion in sodium chloride there is one chloride ion.
Ionic compounds have no overall charge. The atoms must react in the correct ratio. This is shown in the dot and cross diagram.
When sodium reacts with oxygen the oxide has a charge of -2. Each sodium ion has a charge of +1.
The slideshow shows dot and cross diagrams for the ions in sodium chloride, magnesium oxide and calcium chloride.