There was no pressure. It was just another day in the recording studio.

That was the key to writing Ed Sheeran’s “Shape of You,” which has been on the Hot 100 since it was released on Jan. 6, and topped Billboard’s year-end singles chart. It’s a tale of romance sketched in mundane details — “now my bedsheets smell of you” — with four chords delivered in plinking, dancehall-tinged syncopation. The song has drawn more than 2.8 billion views on YouTube and is also the most-played track ever on Spotify, with more than 1.5 billion streams.

Mr. Sheeran thought he already had enough songs for “÷,” the album he released this year, and he was pondering the final selections. As a diversion, he set up a recording session for his sideline: supplying songs to other performers. “I didn’t make this song to be mine to sing,” Mr. Sheeran said.

A singer Mr. Sheeran had been touring with, Anne-Marie, directed him toward the producer Steve Mac, a longtime British hitmaker who has worked with the singer Susan Boyle, the electronic group Clean Bandit and the Irish boy band Westlife, among many others. Mr. Mac co-wrote Westlife’s “Flying Without Wings,” which, Mr. Sheeran said, is “one of my favorite songs of all time.”

Mr. Sheeran also invited a longtime friend with whom he has written hundreds of songs, Johnny McDaid, a member of Snow Patrol, to the session at Mr. Mac’s Rokstone Studios in West London. “I don’t think we’ve ever been together and not written a song,” Mr. McDaid said. “It’s kind of the way we communicate with each other.”

Like many current pop hits, “Shape of You” was written in a brainstorming session where ideas are developed or discarded fast, with computers and instruments close at hand and recorders running. “The best songs that I’ve ever written, I don’t really remember writing,” Mr. Sheeran said. “They take like 20 minutes and then they’re just done. And then you move on to the next thing.”

The New York Times

Fifteen minutes after Mr. Sheeran met Mr. Mac in the studio, “Shape of You” was underway. Mr. Mac came up with the core keyboard riff, playing it with the log-drum sound that happened to be on his synthesizer at the time, hinting at a Caribbean-flavored beat that was already popular: Since the song wasn’t going to be for him, Mr. Sheeran didn’t mind sounding a little derivative.

Mr. Sheeran plays his concerts solo with a looping device, performing and then layering all the parts live; he writes songs the same way, stacking and nesting motifs. “Within 30 seconds Ed was firing melodies out,” Mr. McDaid said. “Ed writes like nobody else in the world. He has a picture of the song in his mind before he’s even articulated it.”

Along with melodies came percussion created by Mr. Sheeran tapping, slapping or strumming his guitar with the strings damped. Mr. Mac was surprised to find that Mr. Sheeran didn’t need to hear what he had already constructed. “He’s not actually layering over the top,” Mr. Mac said. “He’s doing one part, then he does the next part, then he does the next part. And then he says, ‘Put all of those on top of each other.’”

The vocal lines also bounced against the beat, adding more syncopation “like a mantra,” Mr. McDaid said. “Like a heartbeat that happens inside it.”

The song was taking on a rhythm-and-blues feel; Mr. Sheeran started thinking of it as something for a female harmony group, or as a male-female duet, or maybe a song for Rihanna. As they were working, the collaborators realized that the emerging chorus melody resembled TLC’s 1999 hit “No Scrubs”; at one point they were calling the song-in-progress “TLC.” Mr. Sheeran said that negotiations to add credit for the songwriters of “No Scrubs” — Kandi Burruss, Tameka Cottle and Kevin Briggs — began well before the song was released, but weren’t finalized until after it came out. “It just took a while for it to happen,” he said.

The melodies started out as wordless syllables. But Mr. Sheeran’s diaristic side emerged in the first verse: “All the people I know that have met people in pubs, and actually had a conversation, have ended up in long relationships,” he said. The second verse, about thriftily sneaking a plastic bag into an all-you-can-eat Chinese buffet, was a bit he saw in a British TV series called “Fresh Meat,” Mr. Sheeran said.

He also came up with what he thought would be a good phrase for a chorus: “I’m in love with your body.”

Mr. Mac and Mr. McDaid weren’t convinced. “‘I’m in love with your body,’ on its own with no addendum, with nothing at the end or no preface, felt objectifying to me,” Mr. McDaid said. “It felt like that’s the thing — it’s just physical, it’s nothing else.” He said “the shape of you,” a phrase common in Northern Ireland, where he’s from, “can say ‘whatever you are, whatever it is. I’m in love with you.’ You know, it’s the shape of who you are figuratively.”

Mr. Mac gave the collaborators a challenge: to use the same four chords throughout, not switching to a major key for the chorus. “So we used dynamics and we used lyric and rhythm to change what happens in the song, as opposed to using chord changes,” Mr. McDaid said.

They added parts around the keyboard riff and the guitar-tapping: plucked strings, backup vocal syllables, a kick drum. But they were careful to keep the song uncluttered. “If there’s only a vocal and one sound, that’s going to sound much louder on radio than if you have a hundred sounds,” Mr. Mac said. “If the lyric’s good enough, and the melody’s crazy, and you’ve got one sound showing where it’s going to go, you don’t need much more than that.”

After about 90 minutes, they had recorded the complete song. “It was the best hour-and-a-half of my life,” Mr. Mac said.

They wrote four more tracks that day, destined for other acts: Liam Payne, DJ Snake, a duet for Faith Hill and Tim McGraw. Mr. Sheeran thought “Shape of You” was “fun” and it might be good for Rudimental, which like Mr. Sheeran is on the Atlantic label — perhaps as a duet with Rihanna. He played it for the president of Atlantic UK, Ben Cook. And he got a fateful response.