WRITING CHEMICAL FORMULAS OF IONIC COMPOUNDS
When elements form ionic compounds the electrons move from the metal to the non-metal atoms. The POSITIVE charged metals are attracted to the NEGATIVE charged non-metals and this attraction form the ionic bond. Ions will continue to attract other ions until all of the charges are balanced - that is until every positive charge is balanced by a negative charge.
In the compound,
there is a transfer of electrons, and then the electric charges are balanced.