Elements primarily combine to form compounds through two main types of chemical bonding: ionic bonding and covalent bonding. A compound is any molecule that is made up of two or more different elemental atoms.
In order for most atoms to become stable, they must bond with other atoms that are available. Stable atoms have complete outer orbitals. Since metallic atoms typically have excess electrons in their outer orbitals, they tend to try and donate electrons to nonmetals through a process called ionic bonding. Nonmetal elements are typically short electrons and will covalently bond to each other by sharing electrons. Once a bond is made between atoms of different elements, a compound has been formed.