Atoms tend to gain or lose electrons to obtain a stable, eight-electron configuration in their outer shells.