Octet rule

The octet rule is a simple chemical rule of thumb that states that atoms tend to combine in such a way that they each have eight electrons in their valence shells, giving them the same electronic configuration as a noble gas. The rule is applicable to the main-group elements, especially carbon, nitrogen, oxygen, and the halogens, but also to metals such as sodium or magnesium. In simple terms, molecules or ions tend to be most stable when the outermost electron shells of their constituent atoms contain eight electrons.

History
In the late 19th century it was known that coordination compounds (formerly called “molecular compounds”) were formed by the combination of atoms or molecules in such a manner that the valencies of the atoms involved apparently became satisfied. In 1893, Alfred Werner showed that the number of atoms or groups associated with a central atom (the “co-ordination number”) is often 4 or 6; other coordination numbers up to a maximum of 8 occur, but less frequently. In 1904 Richard Abegg formulated what is now known as Abegg's rule, which states that the difference between the maximum positive and negative valences of an element is frequently eight. This rule was used later in 1916 when Gilbert N. Lewis formulated the “octet rule” in his cubical atom theory.

Overview
In short, an element's valence shell is full and most stable when it contains eight electrons (this stability is the reason that the noble gases are so unreactive). Note that a "full shell" means that there are the eight electrons in the valence shell when the next shell starts filling, even though higher subshells (d, f, etc.) have not been filled. There can be at most eight valence electrons in a ground-state atom because p subshells are always followed by the s subshell of the next shell. This means that once there are 8 valence electrons (when the p subshell is filled), the next additional electron goes into the next shell, which then becomes the valence shell.

A consequence of the octet rule is that atoms generally react by gaining, losing, or sharing electrons in order to achieve a complete octet of valence electrons. Reaction of atoms occurs primarily in two ways: ionically and covalently.

Some of the atoms for which the octet rule are most useful are:
 * Carbon, C
 * Oxygen, O
 * The Halogens, F, Cl, Br, I

Exceptions

 * The duet rule of the first shell - the noble gas helium has two electrons in its outer shell, which is very stable. (Since there is no 1p subshell, 1s is followed immediately by 2s, and thus shell 1 can only have at most 2 valence electrons). Hydrogen only needs one additional electron to attain this stable configuration, while lithium needs to lose one.
 * Electron deficiency occurs in covalent compounds when an atom has fewer than eight electrons, and has no unpaired electrons with which to make more bonds. This is frequently seen in boron compounds, which often only have 6 electrons in the valence shell (e.g. BF3), and also occurs in some reactive species like carbenes.
 * Free radicals (e.g. nitric oxide) contain one or more atoms which have an odd number of electrons.
 * Atoms with 3 or more electron shells can accommodate more than eight electrons in their outer shell (hypervalency). Examples include:
 * Phosphorus in phosphorus pentachloride, PCl5.
 * Sulfur in sulfur hexafluoride, SF6.
 * The 18-Electron rule overrides the octet rule in transition metals.