Question: When atoms combine in a way where they each have eight electrons, what rule are they following?
About the article "Chemistry", section "Bonding".

Candidate passages:
The octet rule is a chemical rule of thumb that states that atoms of low (<20) atomic number 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.
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.
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 these four electrons are counted in both the carbon octet and the oxygen octet. 
Atoms sticking together in molecules or crystals are said to be bonded with one another.
A chemical bond may be visualized as the multipole balance between the positive charges in the nuclei and the negative charges oscillating about them.
More than simple attraction and repulsion, the energies and distributions characterize the availability of an electron to bond to another atom.
A chemical bond can be a covalent bond, an ionic bond, a hydrogen bond or just because of Van der Waals force.
Each of these kinds of bonds is ascribed to some potential.
These potentials create the interactions which hold atoms together in molecules or crystals.
In many simple compounds, Valence Bond Theory, the Valence Shell Electron Pair Repulsion model (VSEPR), and the concept of oxidation number can be used to explain molecular structure and composition.
An ionic bond is formed when a metal loses one or more of its electrons, becoming a positively charged cation, and the electrons are then gained by the non-metal atom, becoming a negatively charged anion.
The two oppositely charged ions attract one another, and the ionic bond is the electrostatic force of attraction between them.
For example, sodium (Na), a metal, loses one electron to become an Na+ cation while chlorine (Cl), a non-metal, gains this electron to become Cl-.
The ions are held together due to electrostatic attraction, and that compound sodium chloride (NaCl), or common table salt, is formed.
In a covalent bond, one or more pairs of valence electrons are shared by two atoms: the resulting electrically neutral group of bonded atoms is termed a molecule.
Atoms will share valence electrons in such a way as to create a noble gas electron configuration (eight electrons in their outermost shell) for each atom.
Atoms that tend to combine in such a way that they each have eight electrons in their valence shell are said to follow the octet rule.
However, some elements like hydrogen and lithium need only two electrons in their outermost shell to attain this stable configuration; these atoms are said to follow the "duet rule", and in this way they are reaching the electron configuration of the noble gas helium, which has two electrons in its outer shell.
Similarly, theories from classical physics can be used to predict many ionic structures.
With more complicated compounds, such as metal complexes, valence bond theory is less applicable and alternative approaches, such as the molecular orbital theory, are generally used.
See diagram on electronic orbitals.
  Octet (computing), a grouping of eight bits  Octet rule, chemical theory stating that atoms tend to combine so they each have eight valence electrons  Octet stream, alternative name for byte stream  Octet truss, type of space frame  
Counting electrons.
The total number of electrons represented in a Lewis structure is equal to the sum of the numbers of valence electrons on each individual atom.
Non-valence electrons are not represented in Lewis structures.
Once the total number of available electrons has been determined, electrons must be placed into the structure.
They should be placed initially as lone pairs: one pair of dots for each pair of electrons available.
Lone pairs should initially be placed on outer atoms (other than hydrogen) until each outer atom has "eight" electrons in bonding pairs and lone pairs; extra lone pairs may then be placed on the central atom.
When in doubt, lone pairs should be placed on more electronegative atoms first.
Once all lone pairs are placed, atoms - especially the central atoms - may not have an octet of electrons.
In this case, the atoms must form a double bond; a lone pair of electrons is moved to form a second bond between the two atoms.
As the bonding pair is shared between the two atoms, the atom that originally had the lone pair still has an octet; the other atom now has two more electrons in its valence shell.
Lewis structures for polyatomic ions may be drawn by the same method.
When counting electrons, negative ions should have extra electrons placed in their Lewis structures; positive ions should have fewer electrons than an uncharged molecule.
When the Lewis structure of an ion is written, the entire structure is placed in brackets, and the charge is written as a superscript on the upper right, outside the brackets.
A simpler method has been proposed for constructing Lewis structures eliminating the need for electron counting: the atoms are drawn showing the valence electrons; bonds are then formed by pairing up valence electrons of the atoms involved in the bond-making process; and anions and cations are formed by adding or removing electrons to/from the appropriate atoms.
A trick is to count up valence electrons, then count up the number of electrons needed to complete the octet rule (or with hydrogen just 2 electrons), then take the difference of these two numbers and your answer is the number of electrons that make up the bonds.
The rest of the electrons just go to fill all the other atoms' octets.
Another simple and general procedure to write Lewis structures and resonance forms has been proposed. 
In the early 20th century, the American chemist Gilbert N. Lewis began to use dots in lecture, while teaching undergraduates at Harvard, to represent the electrons around atoms.
His students favored these drawings, which stimulated him in this direction.
From these lectures, Lewis noted that elements with a certain number of electrons seemed to have a special stability.
This phenomenon was pointed out by the German chemist Richard Abegg in 1904, to which Lewis referred to as "Abegg's law of valence" (now generally known as Abegg's rule).
To Lewis it appeared that once a core of eight electrons has formed around a nucleus, the layer is filled, and a new layer is started.
Lewis also noted that various ions with eight electrons also seemed to have a special stability.
On these views, he proposed the rule of eight or octet rule: "Ions or atoms with a filled layer of eight electrons have a special stability".
Moreover, noting that a cube has eight corners Lewis envisioned an atom as having eight sides available for electrons, like the corner of a cube.
Subsequently, in 1902 he devised a conception in which cubic atoms can bond on their sides to form cubic-structured molecules.
In other words, electron-pair bonds are formed when two atoms share an edge, as in structure C below.
This results in the sharing of two electrons.
Similarly, charged ionic-bonds are formed by the transfer of an electron from one cube to another, without sharing an edge A.
An intermediate state B where only one corner is shared was also postulated by Lewis.
Hence, double bonds are formed by sharing a face between two cubic atoms.
This results in the sharing of four electrons.
In 1913, while working as the chair of the department of chemistry at the University of California, Berkeley, Lewis read a preliminary outline of paper by an English graduate student, Alfred Lauck Parson, who was visiting Berkeley for a year.
In this paper, Parson suggested that the electron is not merely an electric charge but is also a small magnet (or "magneton" as he called it) and furthermore that a chemical bond results from two electrons being shared between two atoms.
This, according to Lewis, meant that bonding occurred when two electrons formed a shared edge between two complete cubes.
On these views, in his famous 1916 article "The Atom and the Molecule", Lewis introduced the “Lewis structure” to represent atoms and molecules, where dots represent electrons and lines represent covalent bonds.
In this article, he developed the concept of the electron-pair bond, in which two atoms may share one to six electrons, thus forming the single electron bond, a single bond, a double bond, or a triple bond.
In Lewis' own words:Moreover, he proposed that an atom tended to form an ion by gaining or losing the number of electrons needed to complete a cube.
Thus, Lewis structures show each atom in the structure of the molecule using its chemical symbol.
Lines are drawn between atoms that are bonded to one another; occasionally, pairs of dots are used instead of lines.
Excess electrons that form lone pairs are represented as pair of dots, and are placed next to the atoms on which they reside:To summarize his views on his new bonding model, Lewis states:The following year, in 1917, an unknown American undergraduate chemical engineer named Linus Pauling was learning the Dalton hook-and-eye bonding method at the Oregon Agricultural College, which was the vogue description of bonds between atoms at the time.
Each atom had a certain number of hooks that allowed it to attach to other atoms, and a certain number of eyes that allowed other atoms to attach to it.
A chemical bond resulted when a hook and eye connected.
Pauling, however, wasn't satisfied with this archaic method and looked to the newly emerging field of quantum physics for a new method.
In 1927, the physicists Fritz London and Walter Heitler applied the new quantum mechanics to the deal with the saturable, nondynamic forces of attraction and repulsion, i.e., exchange forces, of the hydrogen molecule.
Their valence bond treatment of this problem, in their joint paper, was a landmark in that it brought chemistry under quantum mechanics.
Their work was an influence on Pauling, who had just received his doctorate and visited Heitler and London in Zürich on a Guggenheim Fellowship.
Subsequently, in 1931, building on the work of Heitler and London and on theories found in Lewis' famous article, Pauling published his ground-breaking article "The Nature of the Chemical Bond" (see: manuscript) in which he used quantum mechanics to calculate properties and structures of molecules, such as angles between bonds and rotation about bonds.
On these concepts, Pauling developed hybridization theory to account for bonds in molecules such as CH4, in which four sp³ hybridised orbitals are overlapped by hydrogen's "1s" orbital, yielding four sigma (σ) bonds.
The four bonds are of the same length and strength, which yields a molecular structure as shown below:Owing to these exceptional theories, Pauling won the 1954 Nobel Prize in Chemistry.
Notably he has been the only person to ever win two unshared Nobel prizes, winning the Nobel Peace Prize in 1963.
In 1926, French physicist Jean Perrin received the Nobel Prize in physics for proving, conclusively, the existence of molecules.
He did this by calculating Avogadro's number using three different methods, all involving liquid phase systems.
First, he used a gamboge soap-like emulsion, second by doing experimental work on Brownian motion, and third by confirming Einstein’s theory of particle rotation in the liquid phase.
In 1937, chemist K.L.
Wolf introduced the concept of supermolecules ("Übermoleküle") to describe hydrogen bonding in acetic acid dimers.
This would eventually lead to the area of supermolecular chemistry, which is the study of non-covalent bonding.
In 1951, physicist Erwin Wilhelm Müller invents the field ion microscope and is the first to see atoms, e.g.
bonded atomic arrangements at the tip of a metal point.
In 1999, researchers from the University of Vienna reported results from experiments on wave-particle duality for C60 molecules.
The data published by Zeilinger et al.
were consistent with de Broglie wave interference for C60 molecules.
This experiment was noted for extending the applicability of wave–particle duality by about one order of magnitude in the macroscopic direction.
In 2009, researchers from IBM managed to take the first picture of a real molecule.
Using an Atomic Force Microscope|atomic force microscope every single atom and bond of a pentacene molecule could be imaged.