Atoms gain or lose electrons to achieve a stable electron configuration, typically the configuration of the nearest noble gas. When atoms gain electrons, they become negatively charged ions, and when they lose electrons, they become positively charged ions.