The song was composed in a house on Blue Jay Way in the Hollywood Hills above L.A. on the foggy night of August 1st, 1967. The house had a Hammond organ in it and, while waiting for friend Derek Taylor to arrive, George put it to good use, writing lyrics inspired by the situation.
The Beatles began recording songs for their upcoming film for television a few weeks later. On September 6th, after hours of work on I Am the Walrus, the group turned their attention to George's composition. A good deal of rehearsal resulted in the basic track being recorded in just one take, with Ringo on drums, Paul on bass and George playing a Hammond organ. The next night, a reduction mix brought the song to take two before the addition of George's lead vocal. Another reduction mix then brought the track to take three before John and Paul's backing vocals were added. All of the vocals were subjected to an extreme use of ADT (artificial double tracking).
A mono mix of the song at this point was made on September 16th to assist in shooting the sequence in the film where George sits on the ground and pretends to play a chalk-drawn keyboard. But the recording was not yet complete. On October 6th, a cellist was brought into the studio at Abbey Road to add a part presumably scored by producer George Martin, once again getting a classically-trained Western musician to bend notes in an Eastern way, as he had done on his brilliant score for Harrison's Within You Without You earlier in the year. A tambourine was also overdubbed at this session.
Several more attempts at a mono mix were made on October 12th with John Lennon sitting in as producer, but none of them were used. The actual mono mix was done on November 7th after George Martin created a unique stereo mix by simultaneously playing the song backwards and mixing it into the forward-playing soundscape from time to time. A few attempts to make this the mono mix as well were abandoned for some reason, so the two versions are substantially different.
The addition of the cello had also caused some rethinking of the song's sequence in the film. Thus, the boys met at Ringo's house on November 3rd and shot new footage, with each of them taking turns pretending to play a white cello in the backyard, plus some scenes of them watching the original footage being projected onto the bare chest of assistant Mal Evans.