The valence electrons can be counted using a Lewis electron dot diagram as shown at the right for carbon dioxide. The electrons shared by the two atoms in a covalent bond are counted twice, once for each atom. In carbon dioxide each oxygen shares four electrons with the central carbon, two (shown in red) from the oxygen itself and two (shown in black) from the carbon. All these four electrons are counted in both the carbon octet and the oxygen octet.
Example: sodium chloride
Ionic bonding is common between pairs of atoms, where one of the pair is a metal of low electronegativity (such as sodium) and the second a nonmetal of high electronegativity (such as chlorine).