The rule or formula for assigning formal charge to atoms in
is the following:
Formal charge = number of valence electrons - (number of lone-pair
electrons + 1/2 number of bonding electrons)
Note that "lone pair electrons" are also known as "nonbonding
pairs" or "unshared pairs".
Another rule that is very important to bear in mind is that the
sum of formal charges of the Lewis structure of a molecule or ion
must be equal to the net charge on the molecule or ion. If this
is not the case, there is a mistake either in the formal charge
assignments or in the Lewis structure (probably the wrong number
of valence electrons).
Patterns of formal charge
Although we can easily calculate formal charge according to the
formula above, it is helpful to be able to recognize patterns for
selected elements. For example, carbon with four covalent bonds
and no lone pairs has a formal charge of zero. Similarly, nitrogen
with three covalent bonds and one lone pair and oxygen with two
covalent bonds and two lone pairs both have formal charge of zero.
Furthermore, for any element, converting a lone pair into a covalent
bond changes the formal charge by plus one. Converting a covalent
bond into a lone pair changes the formal charge by minus one.