You need to know the formulae and charges of some common ions. Positive ions: H+, Na+, K+, Ag+, Mg2+, Ca2+, Zn2+, Cu2+, Fe2+, Fe3+, Al3+ and ammonium NH4+. Negative ions: Cl-, O2-, hydroxide OH-, nitrate NO3-, carbonate CO32- and sulfate SO42-.
An ionic compound is electrically neutral overall, because the positive and negative charges balance. To deduce a formula, write the charge of each ion, then find how many of each are needed so the totals cancel. Aluminium ions are 3+ and oxide ions are 2-. The smallest total that both go into is 6, so the compound contains two aluminium ions and three oxide ions: Al2O3.
If more than one of a compound ion (an ion made of several atoms) is needed, its formula is put in brackets with the number after it. Calcium ions are 2+ and hydroxide ions are 1-, so two hydroxide ions are needed for each calcium ion: Ca(OH)2. Aluminium sulfate needs two Al3+ (total 6+) and three SO42- (total 6-), so it is Al2(SO4)3. Do not use brackets when only one is needed, as in Na2SO4.