How do the best noise cancelling headphones work?
A microphone is placed near the ear and it produces a sound called an anti-noise wave. When this wave collides with the wave from the actual music source they cancel each other out. In addition, it causes a new wave, which eliminates the sounds you do not want to hear by filtering in only the clean aspects of the music. If you are interested in more technical details, you can refer to the vendor’s website.