As we know that atoms are made up of electrons and every element has different no. of electrons present in their shells. Now in universe every element wants to be stable. So for stability of atom of an element they require to have 8 electrons in their valence shells. So they combine together to form bonds and during bond formation they gain or lose electrons to be stable.
hope this helpss u :)