It is a statement used in chemistry, created by the chemical physicist Gilbert Newton Lewis, which states that the tendency of the ions of the elements of the periodic system is to determine their final energy levels with eight electrons, acquiring a stable configuration very similar to that of a noble gas. The octet rule also applies to the creation of bonds between atoms and depending on the nature of the bonds, it will be the behavior and properties of the molecules.
This rule indicates that two equal atoms that are bonded together can develop a certain organization, so that at the moment of generating the bond by the separation of the pairs of electrons each of the atoms has the structure of a noble gas, therefore both atoms in their last energy shell will be surrounded by eight electrons.
For the octet to be fulfilled, a series of processes must occur. First it is through the transfer of electrons, it occurs when the atoms form cations and lose electrons and in their place others gain them and give rise to anions, for this to happen it is required that the electronegative difference between atoms has a high value so that the atom with a lower electronegative charge loses electrons and the other acquires them, this can occur in metals or in non-metals with a high value of electronegativity. In the case of nonmetals, both types of atoms must acquire a greater number of electrons in order to complete the outer shell, for this to happen both must share electrons.
The octet rule allows proposing approximations about the structure of certain compounds, but, as we already know, nature is changeable and there may be exceptions that do not comply with the rules established by humans.
The atoms in certain compounds that do not comply with the provisions of the rule are nitrogen, fluorine, oxygen, sulfur, boron and hydrogen.
In the case of nitrogen, who is a gas that originates from the combustion of fuel in cars has eleven electrons in its valence and since the octet states that electrons must be arranged in even numbers, having an odd number of electrons does not comply with the rule.