McCartney said, "I wanted [the medley] to end with a little meaningful couplet, so I followed the Bard and wrote a couplet." In his 1980 interview with Playboy, John Lennon acknowledged McCartney's authorship by saying, "That's Paul again ... He had a line in it, 'And in the end, the love you get is equal to the love you give,' which is a very cosmic, philosophical line. Which again proves that if he wants to, he can think." Lennon misquoted the line; the actual words are, "And, in the end, the love you take/ Is equal to the love you make."
Recording began on 23 July 1969, when the Beatles recorded a one-minute, thirty-second master take that was extended via overdubs to two minutes and five seconds. At this point, the song was called "Ending." The first vocals for the song were added on 5 August, additional vocals and guitar overdubs were added on 7 August, and bass and drums on 8 August, the day the Abbey Road cover picture was taken. Orchestral overdubs were added 15 August, and the closing piano and accompanying vocal on 18 August.
All four Beatles have a solo in "The End", including a Ringo Starr drum solo. Starr disliked solos; he preferred to cater drumwork to whoever sang in a particular performance. The take in which he performed the solo originally had guitar and tambourine accompaniment, but other instruments were muted during mixing giving the effect of a drum solo. The additional instruments were restored for a remix on the Anthology 3 compilation album. The drum solo was also later used at the beginning of "Get Back" on the 2006 album Love.
McCartney, Harrison, and Lennon perform a rotating sequence of three, two-bar guitar solos. The solos begin approximately 53 seconds into the song and end just before the final piano part. Lennon described it in his 1970 interview with Rolling Stone: "There's a nice little bit I played on Abbey Road. Paul gave us each a piece, a little break where Paul plays, George plays and I play." The first two bars are played by McCartney, the second two by Harrison, and the third two by Lennon, then the sequence repeats. Each has a distinctive style which McCartney felt reflected their personalities: McCartney's playing included string bends similar to his lead guitar work on "Another Girl" from the Help! album; Harrison's was melodic with slides yet technically advanced; and Lennon's was rhythmic, stinging, and had the heaviest distortion. Immediately after Lennon's third solo, the piano chords of the final line "And in the end..." begin. Then the orchestration arrangement takes over with a humming chorus and Harrison playing a final guitar solo that ends the song.
"The End" was initially intended to be the final track on Abbey Road, but it is followed by "Her Majesty". In the first practice mix of the medley, constructed on 30 July, "Her Majesty" followed "Mean Mr. Mustard" (on the released version of the album, "Her Majesty" begins with the excised final chord of "Mean Mr. Mustard"). According to sound engineer John Kurlander, McCartney said, "I don't like 'Her Majesty,' throw it away." Kurlander cut it out, but said, "I'd been told never to throw anything away, so after he left I picked it up off the floor, put about 20 seconds of red leader tape before it, and stuck it onto the end of the edit tape." When McCartney heard "Her Majesty" in its new position he liked it and decided that it should remain on the album.