An atom consists of a nucleus containing positively charged particles surrounded by a cloud of negatively charged electrons. Electrons within atoms sit in a series of "shells" around the nucleus, and each shell can contain a fixed number of electrons. Elements that have a full outer shell are said to have a stable electron configuration. Elements with stable electron configurations only occurs within a single column (group 8) of the periodic table. Therefore the vast majority of the elements in the periodic table have unstable electron configurations.
Hydrogen is the simplest element in the periodic table and consists of a single proton and a single electron. The single electron is located in the 1s shell, which can possess two electrons. The hydrogen electronic configuration is therefore not stable. In order to fill the the 1s shell, two hydrogen atoms combine and share the second electron. This is known as covalent bonding and in this case leads to the formation of a hydrogen molecule.
Sodium is in group 1 of the periodic table and each atom includes 11 electrons. A single electron is located in the outer 3s shell, which is capable of holding 2 electrons. Since this is an unstable electron configuration, sodium often loses its outer 3s electron, producing a positively charged ion. Positively and negatively charged ions combine to form molecules. This is known as an ionic bond and in sodium leads to a variety of molecules including sodium chloride.
Carbon is in group 6 of the periodic table and possesses six electrons in total. The outer 2p electron shell is occupied by two electrons. Since 2p shells can contain six electrons, carbon is not in a stable electron configuration. In order for carbon to obtain a stable electron configuration, it must share a further four electrons via covalent bonds. It is this process that leads to the large quantity of carbon compounds, such as methane.
Chlorine is in group 7 of the periodic table and possesses 17 electrons. The outer 3p shell is occupied by five electrons and therefore requires one more electron to have a stable configuration. Chlorine often gains this extra electron at the expense of becoming a negatively charged ion. This means chlorine can combine with any positively charged ion, forming an ionic bond. A good example is sodium chloride, which is also known as table salt.