According to the octet rule, atoms tend to gain, lose or share electrons in order to achieve a full set of valence electrons. When their valence shells gain a full complement of valence electrons, atoms become especially stable. An element tends to take the shortest path to achieving a full valence shell, whether that means gaining or losing an electron.
Atoms are comprised of a nucleus that contains the protons and neutrons with a cloud of electrons that circles the nucleus in orbitals. The outermost orbital shell of an atom is called its valence shell, and the electrons located in that shell are called the valence electrons. A completely filled shell contains eight valence electrons. During chemical reactions, extra valence electrons can be gained from another atom's valence shell, lost, or shared with another element to form chemical bonds. Valence electrons are the highest energy electrons in an atom and are the most reactive.
Elements that are lower in the periodic table, with an atomic number of 20 or lower, are more likely to follow the octet rule. The six noble gases, which are helium, neon, argon, krypton, xenon and radon, have completely filled valence shells and are the most stable elements on the periodic table.