The octet rule states that elements gain or lose electrons to attain an electron configuration of the nearest noble gas. Here is an explanation of how this works and why elements follow the octet rule.
The Octet Rule
Noble gases have complete outer electron shells, which make them very stable. Other elements also seek stability, which governs their reactivity and bonding behavior. Halogens are one electron away from filled energy levels, so they are very reactive.
Chlorine, for example, has seven electrons in its outer electron shell. Chlorine readily bonds with other elements so that it can have a filled energy level, like argon; +328.8 kJ per mole of chlorine atoms are released when chlorine acquires a single electron. In contrast, energy would be required to add a second electron to a chlorine atom.
From a thermodynamic standpoint, chlorine is most likely to participate in reactions where each atom gains a single electron. The other reactions are possible but less favorable. The octet rule is an informal measure of how favorable a chemical bond is between atoms.
Why Elements Follow the Octet Rule
Atoms follow the octet rule because they always seek the most stable electron configuration. Following the octet rule results in completely filled s- and p- orbitals in an atom's outermost energy level. Low atomic weight elements (the first 20 elements) are most likely to adhere to the octet rule.
Lewis Electron Dot Diagrams
Lewis electron dot diagrams may be drawn to help account for the electrons participating in a chemical bond between elements. A Lewis diagram counts the valence electrons. Electrons shared in a covalent bond are counted twice. For the octet rule, there should be eight electrons accounted for around each atom.