Some basic rules:
Ionic compounds always contain a positve and negative ions.
The sum of the charges (the postive and negative charges) must be equal.
The formula is in simplest whole number ratio form.
First step is to write the metal followed by its charge.
Next write the nonmetal with its charge. (charges can be found based on element group on periodic table)
Then balance out the compound according to the charges until it is electrically neutral. This is where you look at the charges on each ion, and multiply the metals and nonmetals accordingly so that the charges add up to zero.