cross exchanging the coefficients and valences of cations and anions with each other in chemical formulas
The formulas for ionic compounds can be predicted from the charges of their ions. Cations and anions combine to form ionic compounds with a ratio of cations to anions that will produce a neutral (uncharged) unit. Generally, compounds are uncharged species.

Most binary ionic compounds are comprised of a metal and a nonmetal. In the most generic case, a metal cation with a charge of $+m$ and a nonmetal anion with a charge of $-n$ will combine in a $n:m$ ratio to balance charge. The example below, I am using $\ce{M}$ to represent a generic metal and $X$ to represent a generic nonmetal.

$$\ce{nM^{m+} + mX^{n-} -&gt; M_n N_m}$$

This ratio guarantees charge balance. In the generic case the total charge of all cations in the formula unit is $+m\cdot n$, while the total charge of all the anions in the unit is $-n\cdot m$. These two values are equal and we get a compound. It is possible that $n:m$ is not the simplest whole number ratio and we can simplify. See some examples:


Calcium $\ce{Ca^2+}$ chloride $\ce{Cl-}$ gives $\ce{CaCl2}$.
Iron(III) $\ce{Fe^2+}$ sulfide $\ce{S^2-}$ gives $\ce{Fe2S3}$.
Magnesium $\ce{Mg^2+}$ oxide $\ce{O^2-}$ gives $\ce{Mg2O2}$, which can be simplified to $\ce{MgO}$.


We need to be careful to only think this way for ionic compounds. Covalent compounds can be more complex, and their are often multiple binary compounds based on varying oxidation state. Additionally, for covalent compounds, we do not simiplify the coefficients to the lowest whole number ratio, as the formula unit describes discrete molecules with fixed composition. 

For example, $\ce{C4H8}$ (butene) is a different compound from $\ce{C2H4}$ (ethylene).