Elements can combine to form a compound, which is a substance in which atoms of two or more elements are bonded together in a certain ratio. There are a very large number of different configurations of atoms that form different compounds. There are two main types of compounds: ionic compounds and molecular compounds. If an atom loses or gains an electron, a charged particle is formed, which is called an ion. The number of protons, which are positively charged particles, in an ion remains the same as in the neutral atom. So, if an atom loses an electron, its net charge becomes positive. Conversely, if an atom gains an electron, its net charge becomes negative. Opposite charges attract, so when a positively charged ion binds to a negatively charged ion through electrostatic forces, or the attraction or repulsion of particles due to their electron charge, the resulting substance is called an ionic compound. Sodium chloride (NaCl), more commonly known as table salt, is an example of an ionic compound. The two elements are bound together by an ionic bond, which is an electrostatic force that holds a positive ion and a negative ion together.
In contrast, neutrally charged atoms can bind together by sharing electrons between them, which is called a covalent bond. A group of atoms held together by one or more covalent bonds is called a molecule. Compounds made of molecules are called molecular compounds. Water (H2O) and carbon dioxide (CO2) are examples of molecular compounds. Molecules are discrete entities and are the smallest possible particle of a pure compound. The molecular mass of a molecule is the sum of the atomic weights of all atoms in the molecule. The molecular mass, also called molar mass, of a molecule of H2O is 18.01258 grams per mole (g/mol).