Molecules are formed through a process called chemical bonding , where atoms share electrons to achieve stability. This can occur through covalent bonds, where electrons are shared between atoms, or through ionic bonds, where electrons are transferred from one atom to another.