Atoms form bonds to complete their so that their outer shell of electrons canbe full.
The first shell of electrons can hold a maximum of two electrons, the second shell can hold a maximum of eight electrons, and the third shell can also hold a maximum of eight electrons.
To get a full shell of electrons elements can either share electrons, or electrons can be transferred (given or taken) between atoms.
If atoms gain or lose electrons, they are called ions.