Atoms bond together by the loss of gain or sharing of Electrons.
When the bond is formed by gain or loss of electron, ionic bond is formed. Here, one atom loses one or more electrons and the other gains the electron(s).
When the bond is formed by sharing of electron, covalent bond is formed between the atoms which share the electrons.