As early as 1916, G.N. Lewis knew that the central nucleus remains unaltered in every atom in the chemical reaction. And it is the electrons present in the outer-nuclear region that are exchanged between the atoms when new bonds are formed.
According to his hypothesis, a filled outer-nuclear shell of the electron in an atom is especially stable. He assumed that all noble gases (He, Ne, Ar, Kr, Xe, Rn) are stable, and it is their electron configuration that guarantees them stability and chemical inertness.
Therefore, Gilbert N. Lewis formulated an ‘octet rule’ that says that the number 8 is the stable outer electronic configuration that the atoms pursue. And to attain this octet outer electron configuration of the nearest noble gas, the atoms gain, share, and lose electrons.
An exception is Helium which prefers the duplet configuration, unlike the octet state.
Achieving octet by losing or gaining electrons- Ionic Bonding
The atoms can attain the stable electronic configuration of their nearest inert gas by losing or gaining electrons.
For example, lithium has one electron (denoted by a dot.) more than the inert gas Helium, which is its nearest inert gas. By losing one electron, it will form a Li+ ion (cation) with an inert gas configuration of Helium.
The Fluorine atom that belongs to the same row of the periodic table as Lithium has seven electrons more than Helium or one electron less by Neon.
Instead of losing all 7 electrons to reach the Helium configuration that would require very high energy, the Fluorine atom prefers to gain one and attain the electronic configuration of Neon. By gaining one electron, the Fluorine atom forms an F- ion (anion) with Neon's inert gas configuration.
When the atoms lose and gain to each other, it gives them a chance to form an ionic bond.
Therefore, when one excess electron of Li is accepted by F, an ionic bond between oppositely charged Li+ and F- ions forms to give LiF, an ionic compound.
Achieving octet by losing or gaining electrons- Covalent Bonding
The atoms that don’t have too much to lose or gain prefer a middle path of sharing by forming a covalent bond. For example, Carbon, Oxygen, and Nitrogen atoms have 4, 5, and 6 outer electrons. They require 4, 3, and 2 more electrons to reach an octet, and they do so by forming covalent bonds between themselves.
A covalent bond is a chemical bond formed between two atoms by sharing their outer valence electrons. By sharing, both the atoms of a covalent bond attain the nearest inert gas configuration.
For example, the Hydrogen atom needs a second electron to achieve a noble gas configuration of Helium. Therefore, when two hydrogen atoms unite, they share their two electrons to form a bond such that each atom has two electrons in its valence shell.
Other combinations are the H atom (less by one electron) with the Cl atom (less by one electron) to form an HCl molecule where H attains duplet, and Cl attains octet configuration.
C atom (less by four electrons) and four H atoms (each less by one electron) combine to form CH4 where C attains octet and H attains duplet configuration.
N atom (less by three electrons) and three H atoms (each less by one electron) combine to form an ammonia (NH3) molecule.
The structures where the covalent bonding is symbolized using dots are called the Lewis structures. In a Lewis structure, each valence electron is shown as a dot.
The shared electrons that form part of the covalent bond are called bond pairs. The bonding pair of electrons is also represented by a dash (-) instead of dots while drawing a molecular structure. (Read the difference between Kekulé and Lewis structures)
The electrons on an atom that refrained from participating in the sharing and subsequent covalent bond formation are called the non-bonding electrons. A non-bonding electron is also known as the lone pair, denoted as two dots on the atom.
For example, Nitrogen only uses three of its five electrons for covalent bonding to form an NH3 molecule. Oxygen used only two of its six electrons to form one water molecule, whereas chlorine only used one of its seven electrons to form HCl. The unused electron pairs on Nitrogen (one), Oxygen (two), and Chlorine/Halogen (three) are its lone pairs.