The atoms in molecules bond to one another through "sharing"of electrons. Ionic compounds on the other had have atoms or molecules that bond to one another through their mutual attraction between positive and negative charges:
Positively charged atoms or molecules are called "cations" and negatively charged atoms or molecules are called "anions". Thus cations and anions attract one another. Conversely, cations repel one another as do anions.
Electrostatic attraction is indiscriminate. That is a cation can attract more than one anion and visa versa. The result is that cation-anions attractions form a large array that we call an ionic compound or "salt". The bonds holding these ions together are called "ionic" bonds. However, this array has a very specific composition completely dictated by the charges on the cations and anions.
Composition of ionic compounds:
The composition of ionic compounds is determined by the requirement that the compounds must be electrically neutral. That is that the charges of the cations and anions must balance or 'cancel" out one another. For example consider sodium cations (Na+) and Chlorine anions (Cl-). Sodium has a positive 1 charge and chloride has a negative 1 charge. Thus one sodium cation cancels one chloride anion resulting in the formula Na1Cl1 or NaCl. This formula is called the "formula unit" since it represents only one unit of the vast NaCl array or lattice. Below are other examples of simple ionic compounds made up of single atom (monatomic) ions:
Polyatomic ions and compounds:
The ionic compounds above were made up of monatomic ions. Molecules can also be ions - polyatomic ions. Most polyatomic ions are anions with one notable exception - the ammoniun cation (NH4+). The composition of salts with polyatomic ions is determined by the same rule as with monatomic ions. A few example are given below:
Note that when there is two or more polyatomic ions in the formula the ion is enclosed with parenthesis "()".