The noble gases are unreactive because of their electron configurations. The noble gas neon has the electron configuration of 1s22s22p6.
American chemist Gilbert Lewis (1875-1946) used this observation to explain the types of ions and molecules that are formed by other elements. He called his explanation the octet rule.
The octet rule states that atoms tend to form compounds in ways that give them eight valence electrons and thus the electron configuration of a noble gas.
An exception to an octet of electrons is in the case of the first noble gas, helium, which only has two valence electrons. This primarily affects the element hydrogen, which forms stable compounds by achieving two valence electrons.
There are two ways in which atoms can satisfy the octet rule. One way is by sharing their valence electrons with other atoms. The second way is by transferring valence electrons from one atom to another. Atoms of metals tend to lose all of their valence electrons, which leaves them with an octet from the next lowest principal energy level.
Atoms form compounds in ways that give them eight valence electrons.
Metals tend to lose electrons to achieve this configuration.
Nonmetals tend to gain electrons to achieve this configuration.