Usually ionic bond is formed between a metal and and a nonmetal and covalent bond formed between 2 nonmetals.
hece NaCl is a ionic compound. since Na is a metal and Cl is a nonmetal. but H2O is a covalent compound. since both Hydrogen and oxygen are nonmetals.
It does not work always. But there is a rule that makes it easy to recognize many compounds as ionic.
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.