Metal atoms have low ionization energy, and nonmetal atoms have high electronegativity, so electrons transfer easily from the nonmetal atom to the metal atom.
Ionic bonding occurs when valence electrons transfer completely between atoms. The metal atoms having low ionization energy, loses electrons and becomes positively charged. On the other hand, the nonmetal atoms having high electronegativity, accepts the lost electrons and becomes negatively charged.