The octet rule states that atoms tend to form compounds because they need eight electrons in their outermost energy levels to achieve stability. These electrons in the outermost energy levels are called valence electrons, and they play important roles in the likelihood of atoms forming compounds.
Eight valence electrons represent the most stable electron configuration, and the elements that already have eight valence electrons in their atoms, which are known as the noble gases, are the most stable and most inactive elements in the periodic table. In forming compounds with other atoms, an atom lacking eight electrons in its outer energy level can gain, lose or share electrons to achieve the stable eight-valence-electron status. The formation of compounds results in each atom in the compound having eight electrons in its outermost energy levels.