An atom's highest energy level contains what are known as "valence electrons." With some exceptions, two or more atoms will bond to either transfer or share their valence electrons so that there is a total of eight.
For example, Sodium has one valence electron, and chlorine has seven. When these two atoms join, they will have an ionic bond, and all eight valence electrons will be present in this bond.