A chemical reaction, at its core, is the forming and breaking of molecular bonds. When two substances combine to become one (for example, when sodium plus chlorine becomes sodium chloride), what is really happening at the deepest level is the formation of molecular bonds. When one substance splits apart into two (water, dihydrogen monoxide, becomes hydrogen and oxygen), what is really happening is the breaking of molecular bonds.
Both can also occur in the same reaction—for example, sodium hydroxide, NaHO, combined with hydrochloric acid, HCl, results in water, H2O, plus sodium chloride, NaCl. The Na splits from the HO and the H splits from the Cl, then the H and HO recombine into H2O and the Na and Cl recombine into NaCl. Two bonds are broken, and then two new bonds are formed. This is what distinguishes a chemical reaction from just physically mixing things; mixtures don't bond together at the molecular level, but chemical compounds do.
What decides which bonds break and which ones form? Well, a really detailed answer involves the quantum mechanics of electrons. The simpler answer is that stronger bonds have a larger gap (a larger binding energy) between the energy of the molecule and the energy of its constituent parts, so they are easier to form and harder to break.