Townshend originally wrote "Baba O'Riley" for his Lifehouse project, a rock opera that was to be the follow-up to The Who's 1969 opera, Tommy. Townshend derived the song from an experimental recording of his Lowrey Berkshire home organ, which the band reconstructed. "Baba O'Riley" was going to be used in the Lifehouse project as a song sung by Ray, the Scottish farmer at the beginning of the album as he gathers his wife Sally and his two children to begin their exodus to London. When Lifehouse was scrapped, many of the songs were released on The Who's 1971 album Who's Next. "Baba O'Riley" became the first track on Who's Next. The song was released as a single in several European countries, but in the United States and the United Kingdom was only released as part of the album.
Drummer Keith Moon had the idea of inserting a violin solo at the coda of the song, during which the style of the song shifts from crashing rock to an Irish folk-style beat. Dave Arbus, of East of Eden, plays the violin in the studio recording. In concert, lead singer Roger Daltrey replaces the violin solo with a harmonica solo. The Who have produced a live version of the song with a violin, provided by Nigel Kennedy, during their 27 November 2000 concert at the Royal Albert Hall.
The song's iconic backing track was derived from deep within the Lifehouse concept. Townshend wanted to input the life information of Meher Baba into a synthesizer, which would then generate music based on that information. That music would have been the backing track for "Baba O'Riley," but in the end, the frenetic sequence was played by Townshend on a Lowrey Berkshire Deluxe TBO-1 organ using its marimba repeat feature. This modal approach used for the synthesizer track was inspired by the work of minimalist composer Terry Riley. The names of Riley and Meher Baba were incorporated into the song title as a tribute by Townshend. Although they never actually did it in concert, The Who considered pulling a person from the audience and programming their vital statistics into a synthesizer that would, in effect, translate that person into a musical theme around which a song could be built (an idea later resurrected as the Lifehouse Method).
"Baba O'Riley" is often called "Teenage Wasteland" after the phrase repeated throughout the song's chorus. "Teenage Wasteland" was in fact a working title for the song in its early incarnations as part of the Lifehouse project, but eventually became the title for a different but related song by Townshend, which is slower and features more lyrics. A version of "Teenage Wasteland" is featured on The Lifehouse Chronicles, a six disc set of music related to the Lifehouse project, and on several Townshend compilations and videos