To form stable compounds, atoms will combine according to the octet rule.
Octet rule:
Atoms in a compound will lose, gain or share electrons in order to
achieve a stable, noble gas configuration.
This rule leads to the formation of two kinds of compounds, ionic and
covalent.
When a metal combines with a non-metal, the resulting bond is an ionic bond.
This is the lose/gain part of the octet rule.
The metal loses electrons and becomes positively charged and the
non-metal gains electrons and becomes negatively charged.
The ionic bond is the force between the oppositely charged particles.
When a non-metal combines with another non-metal they share electrons.
These shared electrons keep the atoms together and are a covalent bond.