The nitrogen bases in DNA and RNA are held together by hydrogen bonds. These bonds form between the nitrogenous bases on opposite strands of the DNA double helix or in RNA molecules. In DNA, for instance, adenine (A) pairs with thymine (T) through two hydrogen bonds, while cytosine (C) pairs with guanine (G) through three hydrogen bonds.
Hydrogen bonds are relatively weak compared to covalent bonds, which makes them perfect for the structure of DNA. This allows the two strands to separate during processes like DNA replication or transcription, yet they remain tightly bound during normal cellular functions. The specific pairing of bases — A with T and C with G — is crucial for the accurate encoding of genetic information, ensuring that when DNA replicates, the genetic code is faithfully passed on.