The wheel has a disk attached to it that rotates (like another brake disk). The outer edge of the disk has serrations, like little teeth, all the way around. The sensor is set close to these teeth.
The sensor is basically a core of iron (like a chunky iron nail), with many coils of copper wire wound around it. Then packaged up in a metal casing to protect it.
It works because as the wheel's teeth rotate past the end of the sensor, it generates an alternating current in the coil (basic physics stuff, same as how a generator works). This is amplified and its variations, tooth by tooth, so to speak, can hence tell how fast the wheel is turning.
The most likely failure is that the copper wire has broken in the winding of the sensor. It's very thin, and gets a lot of vibration on your car.