Here's why:
* Metals tend to lose electrons, forming positively charged ions (cations).
* Nonmetals tend to gain electrons, forming negatively charged ions (anions).
The electrostatic attraction between these oppositely charged ions creates the ionic bond that holds the compound together.
Example:
Sodium (Na), a metal, reacts with chlorine (Cl), a nonmetal, to form sodium chloride (NaCl), table salt. Sodium loses an electron to become Na+, and chlorine gains an electron to become Cl-. The strong attraction between these oppositely charged ions forms the ionic bond.