Hairpin loop structures are common motifs in folded nucleic acids. The 5′-GCGCAGC sequence in DNA forms a characteristic and stable trinucleotide hairpin loop flanked by a two basepair stem helix. To better understand the structure formation of this hairpin loop motif in atomic detail, we employed replica-exchange molecular dynamics (RexMD) simulations starting from a single-stranded DNA conformation. In two independent 36 ns RexMD simulations, conformations in very close agreement with the experimental hairpin structure were sampled as dominant conformations (lowest free energy state) during the final phase of the RexMDs (∼35% at the lowest temperature replica). Simultaneous compaction and accumulation of folded structures were observed. Comparison of the GCA trinucleotides from early stages of the simulations with the folded topology indicated a variety of central loop conformations, but arrangements close to experiment that are sampled before the fully folded structure also appeared. Most of these intermediates included a stacking of the C 2 and G 3 bases, which was further stabilized by hydrogen bonding to the A 5 base and a strongly bound water molecule bridging the C 2 and A 5 in the DNA minor groove. The simulations suggest a folding mechanism where these intermediates can rapidly proceed toward the fully folded hairpin and emphasize the importance of loop and stem nucleotide interactions for hairpin folding. In one simulation, a loop motif with G 3 in syn conformation (dihedral flip at N-glycosidic bond) accumulated, resulting in a misfolded hairpin. Such conformations may correspond to long-lived trapped states that have been postulated to account for the folding kinetics of nucleic acid hairpins that are slower than expected for a semiflexible polymer of the same size.