"Heroes" is the second album in David Bowie's deservedly vaunted "Berlin trilogy" of the late '70s, but it was the only one recorded in the German capital after it was torn in two by Cold War hostilities.

A wall then separated the eastern part of the city (which was under Soviet control) from the west (part of the Federal Republic of West Germany), creating both an ideological and physical demarcation and a sign of conflict between heated rivals. That transformed West Berlin into a study in contrasts, according to Bowie co-producer Tony Visconti.

"It was a stark, scary place," he told Sound on Sound in 2004, "yet it had a very exciting nightlife, with exotic locales such as the Turkish quarter, and it was swarming with artists like Tangerine Dream, who were friends of ours."

This starkness appealed to Bowie. "I find that I have to put myself in those situations to produce any [reasonably] good writing," he told NME in 1977. "I've still got that same thing about when I get to a country or a situation and I have to put myself on a dangerous level, whether emotionally or mentally or physically – and it resolves in things like that: Living in [West] Berlin, leading what is quite a Spartan life for a person of my means, and in forcing myself to live according to the restrictions of that city."

Part of what Bowie found rejuvenating in West Berlin, even in its Cold War state, was the city's art scene. He was particularly drawn to the city's Brucke Museum, which had on permanent display several works by expressionist painter Otto Mueller, including his Liebespaar zwischen Gartenmauern (Lovers Between the Garden Walls), a work Bowie later witnessed recreated outside the studio, with a most intriguing couple.

Work on what would become the "Heroes" LP's title track commenced, with Bowie, collaborator Brian Eno, and the musicians gathered for the album sessions (including guitarist Carlos Alomar) playing an improvised jam, under the supervision of co-producer Visconti.

Watch David Bowie's Video for 'Heroes'

"David's modus operandi would be to throw a bunch of chord changes and a bunch of ideas in a very loose structure at the band," Visconti told Sound on Sound, "and he knew he could rely on those guys to immediately do something. They were jam experts, and so within half an hour they would jam the few chords that David threw at them into a wonderful structure."

Once a basic track emerged from the jam, it was time for overdubs – a process that took an entire week. Part of that process fell to Eno, who gleefully brought in some items from his collection of gadgets.

"Brian brought his EMS Synthi with him, which is a synthesizer built in a briefcase," Visconti explained, "and it has no real keyboard – it's got a kind of flat, plastic keyboard which Brian very rarely used. He used the joystick a lot, and the oscillator banks, and he would do live dialing. They look like combination-safe rotary knobs on the three oscillator banks."

The majestic solo guitar work on the song was performed by King Crimson stalwart Robert Fripp, who had been laying low for a while before receiving a call from Bowie. Fripp told The Daily Telegraph that Bowie asked if he'd be interested in playing some "hairy rock 'n' roll" on the album.

How much hair was involved is a question left to the ages, but according to Bowie biographer Tom Hagler, Fripp "had everyone fascinated when he pulled out a tape measure with musical notes written on it and placed it in front of the amplifier. When the backing track was played, Fripp moved between the marks to get just the right feedback on the right notes."

Visconti remembered the session, and the technique, quite well. "For instance, an 'A' would feed back maybe at about four feet from the speaker, whereas a 'G' would feed back maybe three-and-a-half feet from it," he told Sound on Sound. Fripp had a "strip that they would place on the floor, and when he was playing the note 'F' sharp he would stand on the strip's 'F' sharp point and 'F' sharp would feed back better. He really worked this out to a fine science, and we were playing this at a terrific level in the studio, too. It was very, very loud."

Watch David Bowie Perform 'Heroes' at Live Aid

The culmination of the session was a backing track for a song that at that time had no melody or lyrics. "I had no melody so I only sang the lines I'd written for four or five bars at a time," Bowie told The Guardian in 1977. "Having sung one line, I'd take a breath and do the same thing again and so on to the end. I never knew the complete melody until I'd finished the song and played the whole thing back."

He also had an unexpected catalyst for his words. For quite a while after the release of 1977's "Heroes" LP, Bowie explained his inspiration for the song was an anonymous couple he would see nearly every day during the sessions, kissing on a bench in the shadow of the Berlin Wall – much like the subjects in the Otto Mueller painting he so much appreciated.

"They were obviously having an affair," he told NME, "and I thought of all the places to meet in Berlin, why pick a bench underneath a guard turret on the wall? They'd come from different directions and always meet there. … Oh, they were both from the west, but they had always met right there. And I – using license – presumed that they were feeling somewhat guilty about this affair, and so they had imposed this restriction on themselves, thereby giving themselves an excuse for their heroic act."

Released on Sept. 23, 1977, "Heroes" somehow reached only No. 24 on the U.K. singles chart, and failed to chart at all in the U.S. Over the years, however, it has resonated with listeners across generations and has been covered by many artists. Only later did Bowie admit that he knew the couple displaying their affection so publicly.

It was Tony Visconti and Antonia Maass, a singer hired to provide background vocals on the album in progress. The two were having an affair, and though he wrote one of his most famous songs about espying their tryst, Bowie was initially circumspect in interviews about their identities to protect Visconti, who was married at the time.

"I could see Tony was very much in love with this girl," Tom Hagler quotes Bowie as saying in his book We Could Be: Bowie and His Heroes, "and it was that relationship which sort of motivated the song."

The Most Shocking Rock Star Fashion Reinventions

From David Bowie to Metallica, these are the most shocking rock star fashion reinventions.