It was primarily written by John Lennon, though credited to Lennon/McCartney. Lennon wrote the song at a Transcendental Meditation camp when he couldn't sleep. The Beatles had gone on a retreat to study with the Maharishi Mahesh Yogi in Rishikesh, India. After three weeks of constant meditation and lectures, Lennon missed his soon-to-be wife, Yoko Ono, and wrote this song. The fact it was recorded at three in the morning enhances the sentiment.
The song was recorded at Abbey Road on 8 October 1968 and was completed including all overdubs in this one session. The Beatles also started and completed the Lennon-composed "The Continuing Story of Bungalow Bill" during the same recording session.
At the end of this song, mumbling can be heard that sounds like "Mih ssim, mih ssim, mih ssim. Nam ded see lope." When played backwards, some claim a scared voice intones, "Paul is dead, man, miss him, miss him, miss him...!" although there have been other claims that on different versions of this song, Lennon can be heard mumbling the words "Monsieur, monsieur, monsieur, how about another one?" The mumbling may be Lennon's attempt at speaking in reverse, without physically reversing the sound.