Ionic bonds form when a metal transfers valence electrons to a nonmetal, creating oppositely charged ions that are attracted to each other. Covalent bonds form when two nonmetals share valence electrons to achieve an octet, or full outer shell, such as in H2 or Cl2 molecules. Sodium chloride forms an ionic bond between Na+ and Cl- ions, while water forms covalent bonds by hydrogen atoms sharing electrons with an oxygen atom.