The formal charge of an atom in a molecule is calculated by taking the number of valence electrons that the atom owns and subtracting the number of electrons it's assigned in the Lewis structure, both in bonds and as lone pairs.
- Count the valence electrons the atom has in the unbound state.
- Count the electrons surrounding the atom in the molecule, assigning one electron for each bond and counting lone electrons normally.
- The formal charge is the difference between these counts.
To calculate this for CO, one must consider that carbon, typically having four valence electrons, and oxygen, with six, are assigned a differential number of electrons due to the triple bond and lone pairs. With a formal charge of -1 on carbon and +1 on oxygen in CO, the electron density gets distributed in a way that diminishes the dipole moment, balancing out the effect caused by the difference in electronegativity. The formal charge isn't the actual charge but a bookkeeping tool that, when combined with understanding of electronegativity and Lewis structures, allows chemists to understand the molecular behavior more thoroughly.