American chemical physicist Gilbert Lewis devised the octet rule in 1917; it explains how atoms of different chemical elements combine to form bonds.
This theory proposes that the ions of elements on the periodic table fill their last energy levels with 8 electrons. This way, the molecules achieve stability at the level of their electronic structure.
Thus, elements with high electronegative charges gain electrons until reaching the octet, while those with low electronegativity usually lose them to achieve the same goal.