Kirk Hammett wrote the original guitar riff that developed into “Enter Sandman.”
Hammett's riff was inspired in part by Soundgarden's 1989 album Louder Than Love. The initial idea was a short two-bar figure. Lars Ulrich suggested changing its repetition so that the first bar was played three times and the second appeared only every fourth time, helping create the song's distinctive rhythmic shape.
James Hetfield and Ulrich then helped develop the broader composition, while Hetfield wrote the lyrics. The instrumental arrangement came together relatively quickly, but the vocal melody and words took longer. “Enter Sandman” was among the last songs on the album to receive its final lyrics.
The songwriting credit belongs to Hammett, Hetfield, and Ulrich. That is different from saying that one person wrote the entire song: Hammett originated the central riff, while the finished composition and lyrics resulted from collaboration among the three members.