Octet rule
The octet rule is a chemical rule of thumb that reflects the theory that main-group elements tend to bond in such a way that each atom has eight electrons in its valence shell, giving it the same electronic configuration as a noble gas. The rule is especially applicable to carbon, nitrogen, oxygen, and the halogens; although more generally the rule is applicable for the s-block and p-block of the periodic table. Other rules exist for other elements, such as the duplet rule for hydrogen and helium, or the 18-electron rule for transition metals. The valence electrons can be counted using a Lewis electron dot diagram as shown at the right for carbon dioxide. The electrons shared by the two atoms in a covalent bond are counted twice, once for each atom. In carbon dioxide each oxygen shares four electrons with the central carbon, two (shown in red) from the oxygen itself and two (shown in black) from the carbon. All four of these electrons are counted in both the carbon octet and the oxygen octet, so that both atoms are considered to obey the octet rule. Example: sodium chloride (NaCl) 

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 third and 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 to form Cl−) is 349 kJ per mole of chlorine atoms. Adding a second electron to form a hypothetical Cl2- would require energy, energy that cannot be recovered by the 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), as in Cl−. 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 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 − 349 = +147 kJ mol−1. This energy is easily offset by the lattice energy of sodium chloride: −783 kJ mol−1. This completes the explanation of the octet rule in this case. History 

In 1864, the English chemist John Newlands classified the sixty-two known elements into eight groups, based on their physical properties. 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 "coordination number") is often 4 or 6; other coordination numbers up to a maximum of 8 were known, but less frequent. In 1904, Richard Abegg was one of the first to extend the concept of coordination number to a concept of valence in which he distinguished atoms as electron donors or acceptors, leading to positive and negative valence states that greatly resemble the modern concept of oxidation states. Abegg noted that the difference between the maximum positive and negative valences of an element under his model is frequently eight. In 1916, Gilbert N. Lewis referred to this insight as Abegg's rule and used it to help formulate his cubical atom model and the "rule of eight", which began to distinguish between valence and valence electrons. In 1919, Irving Langmuir refined these concepts further and renamed them the "cubical octet atom" and "octet theory". The "octet theory" evolved into what is now known as the "octet rule". Walther Kossel and Gilbert N. Lewis saw that noble gases did not have the tendency of taking part in chemical reactions under ordinary conditions. On the basis of this observation, they concluded that atoms of noble gases are stable and on the basis of this conclusion they proposed a theory of valency known as "electronic theory of valency" in 1916:

Explanation in quantum theory 

The quantum theory of the atom explains the eight electrons as a closed shell with an s2p6 electron configuration. A closed-shell configuration is one in which low-lying energy levels are full and higher energy levels are empty. For example, the neon atom ground state has a full  shell (2s2 2p6) and an empty  shell. According to the octet rule, the atoms immediately before and after neon in the periodic table (i.e. C, N, O, F, Na, Mg and Al), tend to attain a similar configuration by gaining, losing, or sharing electrons. The argon atom has an analogous 3s2 3p6 configuration. There is also an empty 3d level, but it is at considerably higher energy than 3s and 3p (unlike in the hydrogen atom), so that 3s2 3p6 is still considered a closed shell for chemical purposes. The atoms immediately before and after argon tend to attain this configuration in compounds. There are, however, some hypervalent molecules in which the 3d level may play a part in the bonding, although this is controversial (see below). For helium there is no 1p level according to the quantum theory, so that 1s2 is a closed shell with no p electrons. The atoms before and after helium (H and Li) follow a duet rule and tend to have the same 1s2 configuration as helium. Exceptions 
Many reactive intermediates are unstable and do not obey the octet rule. This includes species such as carbenes, as well as free radicals and the methyl radical (CH3) which has an unpaired electron in a non-bonding orbital on the carbon atom and no electron of opposite spin in the same orbital. Another example is the radical chlorine monoxide (ClO•) which is involved in ozone depletion. These molecules often react so as to complete their octet. Electron deficient molecules such as boranes also do not obey the octet rule but share delocalized electrons in a manner similar to metallic bonding. Although stable odd-electron molecules and hypervalent molecules are commonly taught as violating the octet rule, ab initio molecular orbital calculations show that they largely obey the octet rule (see three-electron bonds and hypervalent molecules sections below). Three-electron bonds 

Some stable molecular radicals (e.g. nitric oxide, NO) obtain octet configurations by means of a three-electron bond which contributes one shared and one unshared electron to the octet of each bonded atom. In NO, the octet on each atom consists of two electrons from the three-electron bond, plus four electrons from two two-electron bonds and two electrons from a lone pair of non-bonding electrons on that atom alone. The bond order is 2.5, since each two-electron bond counts as one bond while the three-electron bond has only one shared electron and therefore corresponds to a half-bond. Dioxygen is sometimes represented as obeying the octet rule with a double bond (O=O) containing two pairs of shared electrons. However the ground state of this molecule is paramagnetic, indicating the presence of unpaired electrons. Pauling proposed that this molecule actually contains two three-electron bonds and one normal covalent (two-electron) bond. The octet on each atom then consists of two electrons from each three-electron bond, plus the two electrons of the covalent bond, plus one lone pair of non-bonding electrons. The bond order is 1+0.5+0.5=2. Hypervalent molecules 

Main-group elements in the third and later rows of the periodic table can form hypercoordinate or  hypervalent molecules in which the central main-group atom is bonded to more than four other atoms, such as phosphorus pentafluoride, PF5, and sulfur hexafluoride, SF6. For example, in PF5, if it is supposed that there are five true covalent bonds in which five distinct electron pairs are shared, then the phosphorus would be surrounded by 10 valence electrons in violation of the octet rule. In the early days of quantum mechanics, Pauling proposed that third-row atoms can form five bonds by using one s, three p and one d orbitals, or six bonds by using one s, three p and two d orbitals. To form five bonds, the one s, three p and one d orbitals combine to form five sp3d hybrid orbitals which each share an electron pair with a halogen atom, for a total of 10 shared electrons, two more than the octet rule predicts. Similarly to form six bonds, the six sp3d2 hybrid orbitals form six bonds with 12 shared electrons. In this model the availability of empty d orbitals is used to explain the fact that third-row atoms such as phosphorus and sulfur can form more than four covalent bonds, whereas second-row atoms such as nitrogen and oxygen are strictly limited by the octet rule. However other models describe the bonding using only s and p orbitals in agreement with the octet rule. A valence bond description of PF5 uses resonance between different PF4+ F− structures, so that each F is bonded by a covalent bond in four structures and an ionic bond in one structure. Each resonance structure has eight valence electrons on P. A molecular orbital theory description considers the highest occupied molecular orbital to be a non-bonding orbital localized on the five fluorine atoms, in addition to four occupied bonding orbitals, so again there are only eight valence electrons on the phosphorus. The validity of the octet rule for hypervalent molecules is further supported by ab initio molecular orbital calculations, which show that the contribution of d functions to the bonding orbitals is small. Nevertheless, for historical reasons, structures implying more than eight electrons around elements like P, S, Se, or I are still common in textbooks and research articles. In spite of the unimportance of d shell expansion in chemical bonding, this practice allows structures to be shown without using a large number of formal charges or using partial bonds and is recommended by the IUPAC as a convenient formalism in preference to depictions that better reflect the bonding. On the other hand, showing more than eight electrons around Be, B, C, N, O, or F (or more than two around H, He, or Li) is considered an error by most authorities. Other rules 
The octet rule is only applicable to main-group elements. Other elements follow other electron counting rules as their valence electron configurations are different from main-group elements. These other rules are shown below:

 The duet rule or duplet rule of the first shell applies to H, He and Li—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. For transition metals, molecules tend to obey the 18-electron rule which corresponds to the utilization of valence d, s and p orbitals to form bonding and non-bonding orbitals. However, unlike the octet rule for main-group elements, transition metals do not strictly obey the 18-electron rule and the valence electron count can vary between 12 and 18. See also 
 Lewis structure
 Electron counting

References 

Chemical bonding
Rules of thumb