Max Martin, pictured at the 2015 Grammy Awards, has written nearly two dozen No. 1 songs, for performers including Britney Spears, Katy Perry, and Taylor Swift. PHOTOGRAPH BY MICHAEL TRAN / FILMMAGIC VIA GETTY

Among the stranger aspects of recent pop music history is how so many of the biggest hits of the past twenty years—by the Backstreet Boys, ’NSync, and Britney Spears to Katy Perry, Taylor Swift, and the Weeknd—have been co-written by a forty-four-year-old Swede. His real name is Karl Martin Sandberg, but you would know him as Max Martin, if you know of him at all, which, if he can help it, you won’t. He is music’s magic melody man, the master hooksmith responsible for twenty-one No. 1 Billboard hits—five fewer than John Lennon, and eleven behind Paul McCartney, on the all-time list. But, while Lennon and McCartney are universally acknowledged as geniuses, few outside the music business have heard of Max Martin.

Presumably this is because Martin writes all of his songs for other people to sing. The fame that Lennon and McCartney achieved by performing their work will never be his, which no doubt is fine with Martin. (He still gets the publishing.) He is the Cyrano de Bergerac of today’s pop landscape, the poet hiding under the balcony of popular song, whispering the tunes that have become career-making records, such as “… Baby One More Time,” for Britney Spears, “Since U Been Gone,” for Kelly Clarkson, and “I Kissed a Girl,” for Katy Perry. The songs he co-wrote or co-produced for Taylor Swift, which include her past eight hits (three from “Red” and five from “1989”), transformed her from a popular singer-songwriter into a stadium-filling global pop star. (The “1989” tour recently passed the hundred-and-fifty-million-dollar mark.)

Martin has thrived in the ghostwriter’s milieu, where the trick is to remain as anonymous as possible, because the public likes to believe that pop artists write their own songs. That the Swede happens to bring to the table an exceptionally large dollop of Jantelagen, the Scandinavian disdain for individual celebrity, makes him especially well-suited to his vocation.

Still, even for a Nordic, it is a powerful act of self-denial to forego the pleasure (and, yes, the fame and attendant adulation) of recording your own songs, and give all your beautiful tunes to other people, who become famous instead. This path is especially difficult when you possess a beautiful singing voice of your own, which Martin does. As one of his early collaborators, the Swedish artist E-Type, says in “The Cheiron Saga,” a 2008 Radio Sweden documentary about Martin and his former colleagues at Cheiron Studios, in Stockholm, “With his own demos, Max Martin singing himself, those would have sold ten million or more, but he wasn’t an artist; he didn’t want to be an artist.”

And yet Martin is known to insist that the artists he works with sing his songs exactly the way he sings them on the demos. In a sense, Spears, Perry, and Swift are all singing covers of Max Martin recordings. They are also among the few people in the world who have actually heard the originals. Countless self-proclaimed performers on YouTube sing Max Martin songs, but there is not a single publicly available video or audio recording of Martin performing his own stuff. (In the course of researching my book “The Song Machine,” I got to hear an actual Max Martin demo, for “… Baby One More Time,” when a record man who had it on his phone played it for me. The Swede sounded exactly like Spears.) Martin’s demos are the missing originals of our musical age—the blank space at the center of the past two decades of pop music.

Sandberg was born in Stenhamra, a suburb of Stockholm, in 1971. His father was a policeman. He later recalled the handful of recordings his parents had in their collection: Elton John’s “Captain Fantastic,” the best of Queen and Creedence Clearwater Revival, “the Beatles one where they look down from the balcony,” Vivaldi’s “Four Seasons,” and Mozart’s “Eine Kleine Nachtmusik.” Put them all altogether and you've got Max Martin.

Sandberg’s older brother was a glam-rock fan, and “he brought home old Kiss cassettes,” Sandberg recalled, in a 2001 interview in Time magazine, which was the first and last time he took part in an English-language profile. Listening to those tapes made young Karl Martin Sandberg want to be a rock star. “I was a hard rocker at that time, and listened to nothing but Kiss,” he told the Swedish documentarian Fredrik Eliasson, in a follow-up to “The Cheiron Saga” that ran on Radio Sweden earlier this year. “I mean, nothing but Kiss. It was like we belonged to a cult: if you listened to anything else, then in principle you were being unfaithful.”

Sandberg learned music through Sweden’s excellent state-sponsored music-education programs, receiving free private lessons in the French horn. (Thirty per cent of Swedish schoolchildren go to publicly funded after-school music programs.) “I first began with the recorder in our community music school,” he remembered in a Radio Sweden interview. “After that I played horn, and participated in the school orchestra. I remember that I started playing brass not so much because I had a calling but because I thought it looked cool.” Eventually, he moved on to drums, then keyboard. He has credited Sweden’s musical-education system with his success, telling Eliasson, “I would not be standing in this place today if it weren’t for the public music school.”

In the mid-eighties, Sandberg became the front man and main songwriter of a glam-metal band called It’s Alive, adopting the stage name Martin White. In the video for the group’s song “Pretend I’m God,” White plays Jesus and enacts a pseudo-crucifixion, doing his best Ozzy Osbourne imitation. While the song must be considered a work of juvenilia, it does at least explain why eighties metal seems to lurk beneath the surface of so many of today’s pop hits.

But Sandberg had a terrible secret, one that he couldn’t share with the rest of the band. He loved pop music. At home, he listened to Depeche Mode’s “Just Can’t Get Enough” and the Bangles’s “Eternal Flame,” which he later told Time was an all-time favorite. “I couldn’t admit to my friends that I liked it,” he said.

In 1994, he met his mentor, a Swedish d.j. who called himself Denniz PoP and co-founded Cheiron Studios. (His real name was Dag Krister Volle; friends called him Dagge.) Denniz realized that Sandberg’s talents lay in songwriting, not performing, and showed him how to use the studio. Denniz was coming off the major hits he had produced for Ace of Base, “All That She Wants” and “The Sign”; one of Sandberg’s first production credits was on “Beautiful Life,” the group’s final hit. By then his mentor had renamed him Max Martin, a drab, forgettable disco name that is almost as bad as Denniz PoP.

Unlike Denniz, who neither wrote nor played music, Martin knew music theory and musical notation. “Martin was very schooled; he could read the notes, write partitions, and do musical arrangements,” E-Type says in “The Cheiron Saga.” “Dagge would say, ‘We need a new influence, so Martin, make us something pretty while E-Type and I run out for some sushi.’ We’d come back and find something so gorgeous that we both almost fell backwards.”