Well, in fact, Shazam wrote an article explaining the internal operation of the algorithm, you can find at this address (pdf).
Basically, they have a huge database of all the songs that the algorithm can recognize, and they create a kind of "hashtag" of music using its spectrogram. Then, when you record part of a song and send it to them, they transfer it according to the same algorithm and try to match it with hashtags that are stored in the database.
Of course, this is much more complicated than that, since they must control the recording noise and the like, but this is the main idea.
Gimly source
share