How does a tachometer work?

A magnet that magnetizes "teeth" of an iron gear located on the motor. In general... The magnet magnetizes the "teeth" as the approach then de-magnetizes as they move away.. which creates an electric field.. The wire attached to the magnet connects to the tachometer which displays the rpm,

There are multiple types out there. The modern, most exact, is to have a laser or infra red light with a receiver on the opposite side. When the wheel ( or shaft rotates) it has a mirror or a tab that obstructs the path of the light every time it revovles ... then there is simply a chip to count the number of obstructions per minute. This one is extremely accurate and can handle some of the highest speeds.

But there are a host of older versions ... many still in use.

One is quite the same as above except there is a magnet on the shaft and a sensor ( Google 'reed switch' for example ) nearby that detects the magnet passing.

Another way is a chip attached to a switch that is physically pushed or contacted by a cog on the shaft.

Still another is to have a generator attached to the shaft and the Tach is actually a voltage meter telling the reading off that generator.

Finalley ... saved this one for last ... chances are you looked up this question because you wanted to know how the oldest Tachs worked back when electrical gear wasn't commonly used in cars and such. How did they pull it off back then? Well here goes: The end of the shaft had 2+ arms attached to the side that are weighted and would swing outward further and further, the faster the shaft rotated. The weights had a collar attached below them that would rise upward, the faster the shaft ran. Still with me? Check out this graphic if you need http:/www.railway-technical.comgovernor.gif the wieghts are the round black objects and the rising collar is green. So now all that is left is to have a hook ( with wheel to reduce friction ) that is hooked in the path of the collar so that it will get pulled up with the collar. The hook is attached to a cable ... on the other end of that cable is ( drum roll ) the sneedle of the Tach ... tugging it against a spring, over more and more as the shaft spins faster and faster. No electricity and no chips involved! Obviously this is somthing of a percision device and only as accurate as its most recent callibration ... but it worked enough. There were even hand held versions, very precise instruments that machinist would press against the axels of gears and shafts to get RPM readings. Now they have little hand held laser devices that are pocket size and much more accurate.