An ionic bond is formed when a metal transfers electrons to a nonmetal to form ions, which attract each other to give a solid compound. The total number of electrons lost by the metal atom(s) equals the total number of electrons gained by the nonmetal atoms.