Lewis structures are drawn to indicate connectivity of the atoms in a molecule and to account for all shared and unshared valence electrons. In general, the Lewis structures that best match the true electronic structures will have eight electrons around all second-row atoms present (the octet rule). Structures with fewer than eight electrons surrounding these atoms are possible, but usually they represent unstable (high-energy) species. Hydrogen atoms can have only two electrons, and structures with more than eight electrons around any atom are possible only for atoms from the 3rd or lower rows of the periodic table.
Based on the octet rule and the number of valence electrons, we can easily deduce that a neutral carbon (4 valence electrons) is tetravalent (forms 4 bonds), a neutral nitrogen (5 valence electrons) is trivalent (forms 3 bonds) and has 1 lone pair, a neutral oxygen (6 valence electrons) is divalent (forms 2 bonds) and has 2 lone pairs, and a neutral fluorine is monovalent (forms one bond) and has 3 lone pairs. Hydrogen forms only one bond (with some rare exceptions), and elements from the 3rd and lower rows follow the examples of the corresponding second row elements.
The situation becomes a bit more complex when the atoms are charged and/or do not satisfy the octet rule. In such cases, a careful accounting of all valence electrons and formal charges is required. Formal charge (FC) is defined as the difference between the number of valence electrons in the neutral atom (see above) and its number of Lewis-structure electrons (LSE), where the electron count includes all unshared electrons on the atom plus half of all the electrons in the bonds to other atoms. This accounting scheme assumes that all shared electrons are shared equally.Some examples for carbon-, oxygen- and nitrogen-based structures are summarized in the table below. In these structures, R stands for a hydrogen or a monovalent carbon-based substituent (such as –CH3, for example), and X can be a divalent (O, for example) or trivalent (N, for example) atom. LSE electrons are shown in pink.