Let us take the example of an ionic compound MgCl2.it consists of cation Mg2+ and anion Cl- . Mg in its pure form consists two extra electrons on of the other hand chlorine is sort of one electron to complete its octet. Hence one magnesium and two chlorine come together to transfer electrons between them and form the ionic compound. Formation of all ionic compounds take place in similar fashion.

The 2 electrons lost by a magnesium atom are gained by chlorine atoms t produce a magnesium ion and 2 chloride ions.
Three general properties of ionic compounds are as follows:
1) Soluble in polar solvents and insoluble in organic solvents.
2) Good conductor in molten form but non-conductor in solid forms.
3) Generally found in crystalline solid forms due to strong force of interaction.