Here's a breakdown:
* Gaining electrons: Nonmetals tend to gain electrons to achieve a full outer shell of electrons, becoming negatively charged ions called anions.
* Losing electrons: Metals tend to lose electrons to achieve a full outer shell, becoming positively charged ions called cations.
These oppositely charged ions then attract each other, forming an ionic bond.
Examples:
* Sodium (Na), a metal, loses one electron to become Na⁺, a cation.
* Chlorine (Cl), a nonmetal, gains one electron to become Cl⁻, an anion.
* These oppositely charged ions then attract each other, forming the ionic compound Sodium Chloride (NaCl), commonly known as table salt.
Note: Atoms can also share electrons to achieve stability, forming a covalent bond. This is common in nonmetal-nonmetal combinations.
In summary, atoms gain or lose electrons to achieve a more stable electron configuration, which is the driving force behind chemical bonding.