Atoms bond because the bonded arrangement has lower energy than the separate atoms. Two hydrogen atoms, each with one electron, can move together until both electrons sit between the two nuclei, attracted to both at once. Pulling them apart again costs 436 kJ per mole of bonds. That cost, the bond energy, is what makes a bond lasting rather than a passing bump between atoms.
There are three main ways to bond, set by the atoms involved. Two nonmetals, both pulling hard on electrons, share pairs between them: a covalent bond, as in H2, H2O and CH4. A metal and a nonmetal differ so much in pull that electrons effectively move over, making ions that attract: an ionic bond, as in NaCl. Metal atoms on their own release their outer electrons into a shared sea that flows around the positive ions: a metallic bond, which is why metals conduct electricity and bend instead of shattering.
A chemical bond holds atoms together; the weaker attractions between separate molecules are not chemical bonds. When ice melts and water boils, the O–H bonds inside each H2O stay intact, since breaking them takes about 463 kJ/mol; only the attractions between molecules, roughly a tenth as strong, are overcome. Steam is still water. If a change produces a new substance, bonds broke; if it only changes the state, the molecules simply moved apart.
Think of it like this. Bonds behave like magnets snapped together: pulling them apart takes work, and letting them snap together gives off energy, felt as a click with magnets and released as heat in chemistry. The three bond types are three ways of making the snap. Unlike magnets, atoms bond only in numbers set by their valence electrons.
Core idea. Atoms hold together because sharing, transferring or pooling their valence electrons lowers their energy; the type of bond, set by which elements are involved, explains a substance's formula, melting point and conductivity.