“Hot n Cold” was written by Perry, Dr. Luke and Max Martin and produced by Dr. Luke and Benny Blanco. It was recorded in December 2007 in three studios: Dr. Luke’s Studios in New York City, Conway Recording Studio in Hollywood, California, and Legacy Recording Studios in New York City. It was mixed in MixStar Studios in Virginia Beach. The collaboration between Perry and Dr. Luke was set up by record executives at Capitol Records, who felt that One of the Boys was lacking an “undeniable smash or two” at the time, and the two co-wrote “I Kissed a Girl” and “Hot n Cold” as a result. Perry revealed that the song was originally considered for release as the album’s first single, before “I Kissed a Girl” was chosen.