A covalent bond is formed when two atoms share one or more pairs of electrons. The condition for the bond to have a high covalent character is that the difference in electronegativity between the two atoms is zero or very small. According to the Lewis theory, the bond that gives rise to the hydrogen molecule can be described as follows:

Both electrons are shared by the two atoms. For simplicity, it is customary to represent the pair of electrons shared by a line (HH).
Consider the fluorine molecule, the electronic configuration of F is 1s 2 2s 2 2p 5 . Of the valence electrons 2s 2 2p 5 only two participate in the bond, the rest remain as non-bonding electrons, also called lone or free pairs. In this way both fluorine atoms acquire a noble gas electronic configuration.

Let's see the example of water, oxygen can form two covalent bonds with hydrogen, both reaching noble gas configuration. The Lewis structure of water is given by:

In the water molecule, oxygen is left with two non-bonding pairs of electrons.

In the proposed examples, it is observed that atoms tend to be surrounded by 8 electrons, with the exception of hydrogen, which is surrounded by 2 electrons. This observation is called the octet rule: "An atom other than hydrogen tends to form bonds until it is surrounded by eight valence electrons."
The octet rule works correctly with the elements of the second period, presenting important exceptions in the elements of the third and successive periods.
Let's look at the octet rule applied to the formation of the ammonia molecule, NH 3 .

The nitrogen atom needs to form 3 covalent bonds with hydrogens to compete for the 8 electrons that give neon its isoelectronic configuration. For their part, hydrogens acquire the isoelectronic configuration to helium.