It uses the power of Solomon, Hercules, Atlas, Zeus, Achilles and Mercury. Either that or it use pattern recognition to compare what you "play" to it against a huge database of music.
Shazam use a system that identifies a songs individual 'fingerprint' even in noisy conditions. I think Shazam are cagey about revealing exactly how it works, but if you have ever recorded a track on Cool Edit (or Similar), you will notice on the recorded waveform there are peaks and troughs that correspond to the drums and musical frequencies. I think Shazam Matches these characteristics to those of the songs on their musical database.