Ionic compounds are usually formed between metals and non-metals.
Metals are highly electropositive and tend to lose electrons. Non-metals,on the other hand, are electronegative and tend to gain electron. So the transfer of electrons take place b/w them, leading to formation of ionic bond.
It is due to the large difference in their electronegativity.
Read