Taylor Swift's 'All You Had To Do Was Stay' was inspired by a dream about her ex.

Taylor Swift

Taylor Swift

The 25-year-old singer admitted the song came to her while she was sleeping, where she imagined that a former boyfriend showed up at her door.

She said: "I had a dream that my ex showed up at my door, knocked on my door, and I opened it up, and I was about ready to launch into the perfect thing to say. And instead, all that would come out of my mouth was that high-pitched chorus of people singing, 'Stay'."

Taylor admitted the dream left her "mortified" but inspired.

She explained in an interview with Ryan Adams for GQ magazine: "You go to say something else, and it's just like 'Stay, stay, stay. And I woke up and I was like, 'Oh, that was mortifying, but that's kind of a cool vocal part.'"

However, Taylor - who counts John Mayer, Harry Styles, Joe Jonas and Jake Gyllenhaal among her celebrity exes - refused to name the man who she refers to in the song.