Compounds that contain both metals and nonmetals are
usually ionic. For example, Na2SO4 contains a metal (Na) and nonmetals (sulfur and oxygen), and so is expected to be ionic. But CO2 and CH4 contain only nonmetals, and are expected to be molecular compounds.
The rule works because metals give up electrons very easily to form positive ions (cations), and nonmetals gain electrons easily to form negative ions (anions). Electron transfer usually occurs when a metal and a nonmetal react, forming an ionic compound.
You have to watch out for a few exceptions.
- NH4Cl is an ionic compound. You might expect it to be molecular because it contains only nonmetals. But it contains the NH4+ (ammonium) ion, combined with a chloride ion.
- Beryllium (Be) compounds are not ionic, even though beryllium is a metal. Be has very tightly bound electrons and it doesn't give them up completely when it forms compounds with nonmetals. There isn't any such thing as a Be2+ ion.
H2SO4 is covalent compound.
The reason why H2SO4 contains only covalent bonds is because in the structure, you have S-H bonds and S-O bonds. These bonds are formed by the sharing of electrons between S and H and S and O. They don't have a tendency to ionize. Only certain groups of atoms have a tendency to ionize and form ionic bonds. Usually, these atoms have VERY different electronegativity.