In order to conduct electricity, a substance needs to have charges that are free-moving. The particles of a substance that is in a solid state of matter move only slightly. Therefore, ionic compounds like sodium chloride (NaCl) do not conduct electricity well when they are solids. However, when in solution or in a molten state, the electrons of ionic compounds are able to move freely. In such conditions, ionic compounds are able to conduct an electrical current.
Ionic compounds are made of positive and negative ions. Ions are charged atoms. Ions are formed to fulfill what is called the octet rule. The octet rule states that, in order to feel stable, all main-group elements want to have eight valence electrons. Valence electrons are the electrons found in the outermost orbital of an atom.
Cations are positively charged ions that have lost electrons. Element that form cations lose their valance electrons in order to fulfill the octet rule. In this way, they drop to the next lower orbital that is full.
Anions are negatively charged ions. Anions are negatively charged because they have gained additional electrons in order to fulfill the octet rule.