Duck Hunt is either the absolute best game from your childhood or that quaint prehistoric game you've heard people talk about and don't understand. But in 1984, when Nintendo released Duck Hunt, it was amazing. Paired with Super Mario Bros., it was the best thing to happen to games for like a decade. But there was always the mystery of how the gun worked. That mystery grew when things didn't go your way because that thing was totally broken.
Well, as the Today I Found Out YouTube channel explains above, the NES Zapper gun was a pretty simple (kind of genius) device. It consisted of nothing but a button and a light sensor.
Here's what happens. When playing Duck Hunt you pull the trigger to shoot a duck out of the air. When that trigger is pulled, the TV screen goes entirely black for one frame. The light sensor uses that black screen as a reference point, which helps it account for the wide variety of lighting situations in the rooms where the game is being played.
In the next frame, the area the duck occupied turns white while the rest of the screen remains black. If the light sensor detects light in that second frame, your gun is on target. If the light sensor does not, the dog is going to laugh at you.
When there are two ducks on the screen, three frames are used. The game will show a black screen, then a black screen with one of the ducks turned into a white square, and then a third frame with the other target illuminated.
That's it. Such a simple device. It's really a shame they've never improved on video games since then. This was the perfect game. Basically everything has been downhill from this cartridge. Everything.