Atoms form ions by gaining or losing electrons to achieve a full outer electron shell like noble gases. Ions then bond to form ionic compounds between metals and nonmetals like NaCl. Covalent bonds form when atoms share electrons to achieve full outer shells, like in H2O. Polyatomic ions, which are ions of two or more bonded atoms, can also participate in ionic bonding, such as Ca(OH)2 which contains hydroxide ions bonding to calcium ions. The number of each type of atom in a compound is shown by subscripts based on the ions formed.