For the most part, atoms aren’t just existing in isolating but interacting with each other, or other groups of atoms. Atoms are trying to reach the most stable (lowest energu) state that they can. Many atoms become stable when their outer shell, the valence shell is filled with the full quota of electrons.
There are four types of chemical bonds: covalent bonds, ionic bonds, hydrogen bonds, and Van der Waals focre bonds (?).
Bond may be strong or weak. Atoms needing a complete outer shell is called the octet rule.
An example may be Carbon which needs four electrons in it’s valence shells so shares two electrons each with oxygen to become CO2 carbon dioxide.
Nitrogen has five electrons in the outer shell, and wants three extra electrons in it’s outer shell to complete the octet rule. It may combine with three hydrogens to become Ammonia which is NH3.