Mariah Carey was in "the loo" when she was inspired to write "Hero."

The singer says the idea for her hit track came to her while she was using the bathroom.

Carey, 38, said: "Sometimes I wake up and in the middle of the night and have an idea and have to get up and record it straight away before I forget it.

"Or with 'Hero,' I was in the studio and someone was telling me about this film 'Hero' with Dustin Hoffman in it. I took a walk to the loo and when I came back I had this idea for a song, and that was what then became 'Hero.'"

Click here for more from News.com.au.