In their simplest form, noise cancelling headphones will simply employ a microphone in each ear piece (configured to pick-up external noise) and add that signal (in anti-phase) to the audio signal being listened to, in instantaneous analogue form. More expensive models may use digital processing, these days real-time instantaneous audio signal processing is cheap to do.
I have a cheap pair somewhere, lost in household junk, which included manual adjustment of the noise cancelling effect, to optimise the performance for a given situation.