Writing and recording
"Enter Sandman" was the first song Metallica had written for their 1991 eponymous album, Metallica. Metallica's songwriting at that time was done mainly by rhythm guitarist James Hetfield and drummer Lars Ulrich, after they gathered tapes of song ideas and concepts from the other members of the band, lead guitarist Kirk Hammett and bassist Jason Newsted. Ulrich's house in Berkeley, California, was used for this purpose. "Enter Sandman" evolved from a guitar riff that Hammett wrote. Originally, the riff was two bars in length, but Ulrich suggested the first bar be played three times. The instrumental parts of the song were quickly finished, but Hetfield did not come up with vocal melodies and lyrics for a long time. The song was among the album's last to have lyrics, and the lyrics featured in the song are not the original; Hetfield felt that "Enter Sandman" sounded "catchy and kind of commercial" and so to counterbalance the sound, he wrote lyrics about "destroy[ing] the perfect family; a huge horrible secret in a family" that included references to crib death. For the first time in Metallica's history, however, Ulrich and producer Bob Rock told Hetfield that they felt he could write better lyrics. Nevertheless, according to Ulrich, the song was the "foundation, the guide to the whole record" even before it had lyrics.
An instrumental demo was recorded on August 13, 1990. The album Metallica was mostly recorded in Los Angeles at One on One Studios, between October 6, 1990, and June 16, 1991, although Ulrich, Hetfield, and Rock also recorded for a week in Vancouver, British Columbia, Canada, between April and May 1991. As the first to be produced by Bob Rock, it was recorded differently than previous Metallica albums; Rock suggested that the band members record in the studio while playing together, rather than separately.
"Enter Sandman" had what Hetfield described as a "wall of guitars"— three rhythm guitar tracks of the same riff played by himself to create a "wall of sound". According to engineer Randy Staub, close to 50 takes of the drums were recorded because Ulrich did not record the song in its entirety, but rather recorded each section of the song separately. Because it was difficult to get in one take the "intensity" that the band wanted, numerous takes were selected and edited together. Staub mentioned that the producing team spent much time in getting the best sound from each part of the room and used several combinations of 40 to 50 microphones in recording the drums and guitars to simulate the sound of a live concert. The bass guitar sound also gained importance with Rock; as Newsted states, Metallica's sound was previously "very guitar-oriented" and that "when he [Rock] came into the picture, bass frequencies also came into the picture." As the first single, "Enter Sandman" was also the first song to be mixed, a task that took roughly ten days because the band and Bob Rock had to create the sound for the entire album while mixing the song.