Algorithms, visualizedExhibit 11

How does Shazam work?

Shazam turns a few seconds of sound into a spectrogram, keeps only its loudest peaks, and pairs them into compact audio fingerprints called hashes. Then it looks the hashes up and picks the song whose matches line up in time, which is why it can recognize a song even through background noise.

Try it: play a clip and watch the matches line up

Pick a song, choose which seconds your “phone” hears, add some pub noise and press Play clip. The page builds the clip’s spectrogram, picks its peaks, pairs them into hashes and looks them up in a tiny database of five made-up songs. Everything is generated in your browser: no microphone, nothing recorded or sent anywhere.

What’s playing
The whole song (60 s): the box is your clipdrag to move it
What your phone heard: spectrogram and peaks

peak peak in a code that lined up with the top match

Peaks found
–
Hashes (peak pairs) made
–
Codes that survived the noise
–
Codes found in some song
–
Top match
Runner-up

Each dot is one code found in both your clip and that song: across is its time in your clip, up is its time in the song.dots on the winning time shift.

Time shifts: song time minus clip time, counted per song

Score per song: the most matching codes that share one time shift

    A simplified model of the method in Avery Wang’s 2003 paper, not Shazam’s real code. The “songs” are 60 seconds of made-up tones; the spectrogram has 0.1-second steps and one row per semitone; a peak is the loudest point within ±0.3 s and ±2 semitones; each peak is paired with up to 5 peaks in the next 2 seconds (the paper’s example uses 10); and a match needs at least 8 codes on one time shift and three times the runner-up. The noise slider is a toy scale, not decibels. Everything is generated from fixed seeds, so the same settings always give the same result.

    Watch: how Shazam recognizes a song in seconds

    Sound becomes a picture, the picture becomes dots, and the dots line up, in under 5 minutes.

    The video loads from YouTube only when you press play. Watch on YouTube

    How does Shazam recognize a song?

    Shazam doesn’t listen for the melody, the lyrics or the singer’s voice. It looks for a pattern of dots. The method was described by Avery Wang, one of Shazam’s co-founders and its Chief Scientist for 18 years, in a 2003 paper called An Industrial-Strength Audio Search Algorithm. It works in a handful of steps:

    1. Turn a few seconds of sound into a spectrogram, a picture of which pitches are loud at each moment.
    2. Throw away almost everything and keep only the peaks, the brightest points.
    3. Pair nearby peaks and turn each pair into a short code called a hash.
    4. Look every hash up in an index built in advance from every song in the catalog.
    5. Pick the song whose matches all share the same time shift. Those form a straight line.

    That last step is the clever part, and it’s what the demo above shows: the right song’s matches line up in a diagonal, and the wrong songs’ matches are scattered dust. The app has evolved since 2003, but this is the idea it was built on.

    What is a spectrogram?

    Sound is air pressure wobbling back and forth, and your phone’s microphone measures it thousands of times a second. You could try to compare those raw numbers with a recording of every song, but it would be hopeless: change the volume, add a little echo or someone talking, and every single number changes.

    So the first step is to turn the sound into a picture. In a spectrogram, time runs left to right, pitch (or frequency) runs bottom to top, and brightness shows how loud each pitch is at each moment. A song becomes a landscape of bright and dark patches. A sustained note is a bright horizontal streak; a drum hit is a short vertical smear across many pitches; a singer’s voice makes a stack of streaks, one for each overtone. In the demo, the top strip is the spectrogram of a whole made-up song, and the bigger picture below it is the part your phone “heard”.

    Why does Shazam keep only the peaks?

    In Wang’s method, most of the spectrogram is then thrown away. Only the peaks are kept: points that are louder than everything around them. What’s left looks like stars on a dark sky, and the paper calls it a constellation map.

    Peaks are chosen because they’re stubborn. Background chatter adds sound, but it rarely moves the loudest parts of the music. Turn up the bass on a speaker and a peak still sits at the same pitch, at the same moment: the paper notes that peaks keep their coordinates through that kind of equalization. Noise will hide some of the dots, and new dots will appear where the noise itself is loud. That’s fine: the method only needs some of the real dots to survive. Push the noise slider in the demo and watch the peak count change while the match holds on.

    What is an audio fingerprint?

    One dot on its own doesn’t say much. A bright spot at a certain pitch? Millions of songs have one. So Shazam pairs the dots up. It picks one peak as an anchor and links it to a few peaks that come shortly after, inside a small window called the target zone. Each pair becomes three numbers: the first pitch, the second pitch and the time between them. Those three numbers are packed into a single 32-bit code called a hash, and each hash is stored together with the moment its anchor occurs in the song. The whole collection of hashes is the song’s fingerprint.

    A pair is far rarer than a single dot. In the paper’s example, pairing adds about 20 bits of information, which makes each code about a million times more specific. With each anchor paired to 10 others, searching becomes about 10,000 times faster than looking up single dots, at the cost of about 10 times as much storage. Notice that the codes use only differences in time, never the absolute time, so the same pair of notes gives the same code wherever your clip happens to start.

    Every song in the catalog is turned into hashes ahead of time and stored in a giant index. Back in 2003, that index already held more than 1.8 million tracks.

    From sound to a match, step by step

    StepWhat it keepsWhy
    RecordA few seconds of air-pressure measurements, thousands per secondThat’s all a microphone gives you
    SpectrogramHow loud each pitch is at each momentTurns sound into a picture you can compare
    Peaks (constellation map)Only points louder than everything around themPeaks survive noise, volume changes and EQ
    Pairs → hashesFirst pitch, second pitch, time gap: one 32-bit code eachA pair is far rarer than a single dot
    LookupEvery song and moment that contains each codeOne index lookup per code, no scanning
    Line up in timeMatches that share one time shift, counted per songChance matches scatter; the real song forms a line

    How does Shazam find the right song so fast?

    Your phone makes the same kind of codes from the few seconds it heard. Each hash is looked up in the index, which answers: these songs contain this code, at these moments. No song is ever compared with your clip from start to finish; each code is a single lookup.

    But by chance, lots of wrong songs share a few codes. The giveaway is timing. Say your clip started 72 seconds into the song. Then every genuine match should turn up in that song exactly 72 seconds later than in your clip. Plot each song’s matches with the time in your clip across and the time in the song up, and the right song forms a clean diagonal line, while wrong songs are scattered dust. That’s the pair of scatter plots in the demo.

    To score each song, Shazam subtracts the two times for every match and counts how many matches share the same time shift. In a histogram of those shifts, the right song shoots up into one tall spike, and the height of that spike is its score. Random matches spread out over every possible shift, so they never pile up. In one of the paper’s tests, a heavily corrupted 15-second clip still gave a clear match when only about 1 to 2 percent of its codes survived.

    It’s fast, too. The paper’s summary speaks of searches taking a few milliseconds per query. Its tests report 5 to 500 milliseconds on a PC with about 20,000 tracks, and a few hundred milliseconds of core search time in the deployed service: well under a second.

    Can Shazam recognize a song in a noisy bar?

    Surprisingly often. To test it, the paper used a database of 10,000 tracks and 250 clips that were 15, 10 or 5 seconds long, then mixed in recorded pub noise at set levels. Half of the 15-second clips were still recognized at about −9 dB signal-to-noise ratio, which means the noise had roughly 8 times the power of the music. With phone-call (GSM) compression added on top, half were still recognized at about −3 dB, with the noise still louder than the music.

    The demo shows the same trade-off in miniature. Turn the noise up and fewer codes survive. A longer clip gives the true song more chances to collect matches on its line, so it holds on at noise levels where a 3-second clip gives up. When the spike in the histogram no longer stands clearly above the rest, the demo says “no confident match” instead of guessing, and pick “A song that isn’t in the database” to see that an unknown song produces only dust.

    Why can’t Shazam recognize humming, live versions or covers?

    Shazam’s blind spot is that it matches one exact recording. A live version or a cover is a different recording, with different peaks at different moments, so it often won’t match the studio track. Humming fails for the same reason: your voice makes completely different dots from the original, even if you hit every note.

    Recognizing a hum needs another approach. Google’s Hum to Search, launched in October 2020, uses machine learning models to turn the audio into a number-based sequence that represents the melody, ignoring the instruments and the tone of the singer’s voice. Shazam’s trick is narrower, but it’s fast and very hard to drown out with noise.

    Does Shazam send my recording to Apple?

    Apple’s privacy page for music recognition says that when you identify a song, Shazam sends a unique audio fingerprint for the request. That fits the method: matching needs the codes, not the sound itself. The demo on this page goes further still: there is no microphone at all, and nothing leaves your browser.

    A short history of Shazam

    It started small. In 2002, Shazam launched in the UK as a phone service: you dialed 2580, held your phone up to the music and got the song’s name and artist back by text message. A year later, Wang published the algorithm behind it. Apple announced it was buying Shazam in December 2017, and the deal closed in 2018. In November 2024, Apple said Shazam had passed 100 billion song recognitions, about 12 for every person on Earth.

    What does the demo simplify?

    Quite a lot, on purpose. Its five songs are made-up tunes built from simple tones, a minute long each, so the whole database fits in your browser. Its spectrogram is coarse, with a tenth of a second per column and one row per semitone, where a real system works with much finer detail. Its noise is a toy: soft hiss plus random blobs of “chatter”, measured on a 0–100 scale rather than in decibels. And its rule for declaring a match (at least 8 codes on one time shift, and three times the runner-up) is a simple stand-in for the statistics a real service would use. The steps are the real ones, though: spectrogram, peaks, pairs, hashes, lookup, and a histogram of time shifts.

    Frequently asked questions

    How does Shazam identify a song?

    It turns a few seconds of sound into a spectrogram, a picture of which pitches are loud at each moment, and keeps only the peaks. It pairs nearby peaks into short codes called hashes (first pitch, second pitch and the time between them) and looks them up in an index built from every song in its catalog. The right song is the one whose matching codes all share the same time shift, so they line up in a diagonal.

    Can Shazam recognize a song in a noisy room?

    Often, yes. In tests described in the 2003 paper behind Shazam, half of the 15-second clips were still recognized when recorded pub noise was mixed in at about −9 dB signal-to-noise ratio, meaning the noise had roughly 8 times the power of the music. It works because noise rarely moves the loudest peaks of the music, and a match needs only some of the codes to survive.

    Why can’t Shazam recognize my humming?

    Because Shazam’s method matches one exact recording. Your voice makes completely different spectrogram peaks from the original track, so the codes don’t match. Live versions and covers often fail for the same reason. Recognizing a hum needs another approach: Google’s Hum to Search, launched in 2020, uses machine learning to turn a melody into a sequence of numbers.

    What is an audio fingerprint?

    A compact summary of a recording that survives noise and compression. In Shazam’s published method, the fingerprint is a large set of hashes. Each one packs the pitch of a spectrogram peak, the pitch of a peak shortly after it and the time between them into a single 32-bit number, tagged with the moment it occurs in the song.

    Who invented the Shazam algorithm?

    Avery Wang, one of Shazam’s co-founders and its Chief Scientist for 18 years. He described the method in “An Industrial-Strength Audio Search Algorithm”, published at the ISMIR conference in 2003. Shazam had launched in the UK the year before as a phone service: you dialed 2580 and got the song’s name back by text message.

    Sources

    Last updated

    Keep exploring