By the combination of metal and non-metal formation of an ionic bond takes place.
In this process, the metal tends to lose the electron which is gained by the non-metals. Thus, metals formed cations while non-metals form anions in the complex.
They are bonded by strong electrostatic forces by which they form ionic bonds.
Example- For the formation of , sodium which is metal loses one electron which forms a cation while non-metal gains the electron to form an anion. Both are oppositely charged compounds and form ionic bonds between them, with electrostatic forces.
Thus, Ionic bonds work by the transfer of electrons from the metal to non-metals which have opposite charges.