The song was written by Ian Dury and Chaz Jankel in Dury's flat in Oval Mansions, London (nicknamed "Catshit mansions" by Dury) that overlooked The Oval cricket ground. The pattern of work adopted by the pair involved Dury presenting Jankel with his hand-typed lyric sheets. According to Jankel in "Sex and Drugs and Rock and Roll: The Life of Ian Dury" he would be repeatedly given the lyric for "Sex and Drugs and Rock and Roll" but Jankel kept rejecting the song, only for it to be at the top of the pile again the next time, only to be rejected again. This went on until Dury sung the song's guitar riff to Jankel and sang the song's title in time with Jankel's riff.