Have you ever wondered why the formation of ionic compounds is exothermic? The quick answer is that the resulting ionic compound is more stable than the ions that formed it. The extra energy from the ions is released as heat when ionic bonds form. When more heat is released from a reaction than is needed for it to happen, the reaction is exothermic.
Understand the Energy of Ionic Bonding
Ionic bonds form between two atoms with a large electronegativity difference between each other. Typically, this is a reaction between metals and nonmetals. The atoms are so reactive because they do not have complete valence electron shells. In this type of bond, an electron from one atom is essentially donated to the other atom to fill its valence electron shell. The atom that "loses" its electron in the bond becomes more stable because donating the electron results in either a filled or half-filled valence shell. The initial instability is so great for the alkali metals and alkaline earths that little energy is required to remove the outer electron (or 2, for the alkaline earths) to form cations. The halogens, on the other hand, readily accept the electrons to form anions. While the anions are more stable than the atoms, it's even better if the two types of elements can get together to solve their energy problem. This is where ionic bonding occurs.
To really understand what's going on, consider the formation of sodium chloride (table salt) from sodium and chlorine. If you take sodium metal and chlorine gas, salt forms in a spectacularly exothermic reaction (as in, don't try this at home). The balanced ionic chemical equation is:
2 Na (s) + Cl2 (g) → 2 NaCl (s)
NaCl exists as a crystal lattice of sodium and chlorine ions, where the extra electron from a sodium atom fills in the "hole" needed to complete a chlorine atom's outer electron shell. Now, each atom has a complete octet of electrons. From an energy standpoint, this is a highly stable configuration. Examining the reaction more closely, you might get confused because:
The loss of an electron from an element is always endothermic (because energy is needed to remove the electron from the atom.
Na → Na+ + 1 e- ΔH = 496 kJ/mol
While the gain of an electron by a nonmetal is usually exothermic (energy is released when the nonmetal gains a full octet).
Cl + 1 e- → Cl- ΔH = -349 kJ/mol
So, if you simply do the math, you can see forming NaCl from sodium and chlorine actually requires the addition of 147 kJ/mol in order to turn the atoms into reactive ions. Yet we know from observing the reaction, net energy is released. What's happening?
The answer is that the extra energy that makes the reaction exothermic is the lattice energy. The difference in the electrical charge between the sodium and chlorine ions causes them to be attracted to each other and move toward one another. Eventually, the oppositely charged ions form an ionic bond with each other. The most stable arrangement of all the ions is a crystal lattice. To break the NaCl lattice (the lattice energy) requires 788 kJ/mol:
NaCl (s) → Na+ + Cl- ΔHlattice = +788 kJ/mol
Forming the lattice reverses the sign on the enthalpy, so ΔH = -788 kJ per mole. So, even though it takes 147 kJ/mol to form the ions, much more energy is released by lattice formation. The net enthalpy change is -641 kJ/mol. Thus, the formation of the ionic bond is exothermic. Lattice energy also explains why ionic compounds tend to have extremely high melting points.
Polyatomic ions form bonds in much the same way. The difference is that you consider the group of atoms that forms that cation and anion rather than each individual atom.