When a metal and a nonmetal come into contact, the metal atom loses one or more of its valence electrons to the nonmetal atom. This transfer of electrons creates positively charged metal ions and negatively charged nonmetal ions. The electrostatic attraction between these oppositely charged ions holds the ionic compound together.
For example, when sodium (a metal) and chlorine (a nonmetal) react, the sodium atom loses its single valence electron to the chlorine atom. This results in the formation of sodium ions (Na+) and chloride ions (Cl-). The electrostatic attraction between sodium ions and chloride ions leads to the formation of the ionic compound sodium chloride (NaCl).
Ionic compounds are characterized by their high melting and boiling points, solubility in polar solvents (such as water), and ability to conduct electricity when dissolved in water or melted.