Ionic compounds contain positive and negative ions.
The number of positive charges must equal the number of negative charges, so that the compound has no overall charge. When the number of charges on the positive ion is the same as the negative ion, they cancel each other out.
When the number of charges is different, a ‘swap and drop’ method can help.
Here are some worked examples of the ‘swap and drop’ method.