Atoms combine to form compounds because of electric forces that attract them to each other. The process by which two atoms link together is called bonding.
Atoms are defined by their number of electrons. An atom of hydrogen has a single electron, while an atom of carbon has six. These electrons are organized into levels, or valence shells. Each shell has a maximum number of electrons it can hold. The first shell holds up to two electrons, while the second holds up to eight, for example. When a shell is not completely full, the atom is attracted to other atoms that can share electrons to fill the empty slots. Carbon can bond with four other atoms, because it has four open slots in its outermost electron shell. This allows atoms to form bonds with many other atoms.