Atoms form ions because they gain or lose electrons to achieve a more stable electronic configuration, usually a full outer electron shell. This process, called ionization, happens because atoms tend to attain stable arrangements similar to noble gases, known as the octet rule, where the outermost shell holds eight electrons (or two for some light elements). Atoms with nearly full or nearly empty outer shells will lose or gain electrons respectively, forming positively charged ions (cations) if they lose electrons, or negatively charged ions (anions) if they gain electrons. This stability also means the atom or ion requires less energy to maintain. For example, metals tend to lose electrons and form cations, while nonmetals tend to gain electrons and form anions. This electron transfer is fundamental in chemical reactions such as the formation of ionic bonds (e.g., NaCl from sodium and chlorine).
In summary, atoms form ions to reach a stable, lower-energy state by completing their outer electron shell, balancing achieving stability and minimizing energy.