The number of valence electrons available in a free atom of an element minus the total for that atom in the molecule (determined by counting lone pairs as two electrons and bonding pairs as one assigned to each atom) is the formal charge on the atom: