"Ghosttown" was written by Madonna, Jason Evigan, Evan Bogart, and Sean Douglas. The song was composed in three days, after Madonna personally requested some studio time with them. Madonna liked Jason Derulo's 2013 single "Talk Dirty" which was co-written by Evigan and Douglas, and hence she decided to collaborate with them. Douglas recalled that they ended up having a "great session", saying "I was incredibly nervous for obvious reasons, but she showed up, was super personable and was ready to work. I basically checked it off my life bucket list." Of their writing session, Madonna explained:
