For example, consider sodium chloride (NaCl). Sodium chloride is composed of sodium ions (Na+) and chloride ions (Cl-). Each sodium ion has a positive charge of +1, while each chloride ion has a negative charge of -1. When sodium and chloride ions combine to form sodium chloride, they do so in a 1:1 ratio, so that for every sodium ion there is one chloride ion. This means that the positive charges of the sodium ions are exactly balanced by the negative charges of the chloride ions, resulting in an overall neutral charge for the compound.
The same principle applies to all other ionic compounds. The positive charges of the cations are always balanced by the negative charges of the anions, ensuring electrical neutrality.