Example: sodium chloride
Ionic bonding is common between pairs of atoms, where one of the pair is a metal of low electronegativity (such as sodium) and the second a nonmetal of high electronegativity (such as chlorine).
A chlorine atom has seven electrons in its outer electron shell, the first and second shells being filled with two and eight electrons respectively. The first electron affinity of chlorine (the energy release when chlorine gains an electron) is +328.8 kJ per mole of chlorine atoms. Adding a second electron to chlorine requires energy, energy that cannot be recovered by formation of a chemical bond. The result is that chlorine will very often form a compound in which it has eight electrons in its outer shell (a complete octet).
A sodium atom has a single electron in its outermost electron shell, the first and second shells again being full with two and eight electrons respectively. To remove this outer electron requires only the first ionization energy, which is +495.8 kJ per mole of sodium atoms, a small amount of energy. By contrast, the second electron resides in the deeper second electron shell, and the second ionization energy required for its removal is much larger: +4562.4 kJ per mole. Thus sodium will, in most cases, form a compound in which it has lost a single electron and have a full outer shell of eight electrons, or octet.
The energy required to transfer an electron from a sodium atom to a chlorine atom (the difference of the 1st ionization energy of sodium and the electron affinity of chlorine) is small: +495.8 − 328.8 = +167 kJ mol−1. This energy is easily offset by the lattice energy of sodium chloride: −787.3 kJ mol−1. This completes the explanation of the octet rule in this case.