Ions form electrically neutral compounds because the number of cations (positively charged ions) is equal to the number of anions (negatively charged ions). These ions are held together by strong electrostatic forces of attraction.
Sodium chloride is an ionic compound made up of positive sodium ions and negative chlorine ions. These ions form a network of ions that is often described as a three-dimensional lattice network of ions. Since the ions are held together by ionic bonds, they are not free to move and conduct electricity. However, when sodium chloride is dissolved in water, the resulting solution conducts electricity because the ions are free to move in the solution, which allows the passage of electric current.