More detail. In a 3-pin fan, the leads are:
Pin 1 (Black wire) Ground
Pin 2 (Red wire) + DC Volts
Pin 3 (Yellow wire) Speed signal
The VOLTAGE on Pin 2 varies from 12 VDC for full speed down to about 5 VDC for minimum speed without stalling.
The Speed signal generated by the motor is sent back to the header on Pin 3. It is a series of pulses 5 VDC high at 2 pulses per revolution. The header merely counts those repeatedly over a fixed time frame and calculates RPM. Accuracy? Fan speeds actually DO vary slightly over time, so some small fluctuation is normal. The calculation SHOULD be correct as long as the timer is reliable and the programming contains the correct scaling constants, but it is possible for those to be wrong, producing a stable error amount.
For 4-pin fans the electrical signals are similar with important differences. However, wire colour coding comes in at least two versions.
Pin 1 Ground (same)
Pin 2 +12 VDC constant
Pin 3 Speed signal (same)
Pin 4 PWM signal
The PWM (Pulse Width Modulation) signal is 5 VDC high and similar to a square wave in that is always either fully on or fully off. However, whereas a square wave is on exactly 50% of the time always, a PWM wave has variable % On time, ranging from 0% (Off always) to 100% (On always). In PWM fan motors for computers, this signal operates at about 22 KHz. Inside the motor case there is a small circuit with a switching chip that uses this PWM signal to turn on and off the flow of current from the fixed 12 VDC line through the motor windings. So the AVERAGE current flow normally is less than the MAX (100% On), and thus the average torque force driving the motor is reduced, reducing its speed and resultant air flow.
As an aside, the way that larger industrial PWM motor drives operate is different. In those systems the motor does NOT have its own switching chip. The actual power supplied to it on cables is switched at the motor control module to achieve the same result. For this reason the makers of computer PWM fans caution you NOT to apply a commercial PWM motor control's output to a computer fan designed differently.
The design and introduction of 4-pin PWM fans includes a couple of important backwards compatibility features to ease their introduction into the market. The physical layout of the connectors is very similar so that you CAN plug either fan type into either header type. The electrical characteristics also are very similar (above) so that either fan type WILL work with some limitations. In the simple cases of connecting a fan to its intended header and signals, they work as designed, but what about the mis-matches? If you plug a 3-pin fan into a 4-pin header it makes NO contact with Pin #4 and gets no PWM signal it could not use, anyway. It does receive a power supply of +12 VDC always (not varying as the 3-pin design intended) so it always runs full speed. You get good-to-overly-much cooling but no ability to reduce that. When you plug a 4-pin fan into a 3-pin header the fan receives NO PWM signal so its chip cannot modify the power flow to the windings. However, that power supply from Pin #2 is VARYING, so the motor speed IS controlled this way, just as a 3-pin fan would be. From a technical perspective this is not ideal, and not the way the motor was designed, but it works.
A small important side note on speed detection. A mobo header figures out speed by counting pulses. It can NOT deal with TWO pulse trains from different fans at the same time because they are never synchronized. So if you use a Splitter or a Hub to connect more than one fan to a header, that device will only send back to the host header the speed signal from ONE of the fans and ignore all the others.
Today virtually all mobo headers have 4 pins. But in BIOS Setup almost all have an option to SET the signal type or MODE used to control fan speed. It can act in either 3-pin Voltage Control Mode (aka DC Mode) or in 4-pin PWM Mode. Many also include an Auto Detect option here. In that setting, at every start-up the header starts the fan at full speed in PWM Mode, then sends out a reduced speed PWM signal and monitors the fan speed signal coming back. If the speed is reduced, this must be a PWM type 4-pin fan and that settles the matter. If the speed does NOT reduce, this must be an older Voltage Control Mode fan, and the header switches to that Mode to enable it to control this fan's speed.
Easy-peasy, except for one important situation with PUMPS. MOST (not all) CPU liquid cooling systems are designed to have the pump run at full speed all the time. Why? IF you have BOTH the Pump and the Rad Fans change their speeds in response to the actual internal CPU temperature, the two actors have different time delays and gain factors, so their actions cannot be co-ordinated. They will "chase" each other around constantly, yielding very poor control. So the PUMP speed is kept constant, and ALL control of CPU cooling is done by altering the speed of the RAD FANS ONLY. Now, how to assure that the PUMP will always run full speed? They are wired just like an older 3-pin Voltage Control Mode fan. So if you plug that into a CPU_FAN header that IS using the newer PWM Mode, it will always run full speed! In many such systems, this makes connecting up such a cooling system easy when done right. You can use a simple Splitter to connect BOTH the PUMP and the RAD FANS to the CPU_FAN header, ensuring that the PUMP is the one item that is plugged into the Splitter's output arm with ALL FOUR pins. That may seem strange, but here's why. An important second function of ALL mobo fan headers is to monitor the fan speed signal it gets - NO speed signal (or, in some cases, a signal slower than some minimum you can set) is understood to mean the fan has FAILED and the CPU may overheat VERY rapidly and be damaged. You get a prominent warning on-screen, and many such systems actually will wait for a SHORT time and then shut down completely to prevent CPU damage. In a liquid-cooled system the important component to monitor for FAILURE is the PUMP. No fluid flow = NO cooling, whereas fluid flow with little or no FAN action at the rad will provide poor cooling allowing the temperature to rise slowly, and that situation WILL be detected by a different protection system based on the actual temperature measurement. So the only speed signal sent back to the CPU_FAN header for failure monitoring MUST be the PUMP speed. With connections made this way, the PUMP, acting just like an older 3-pin fan, will run full speed all the time as intended by most designs. But the 4-pin RAD FANS on that Splitter WILL receive the PWM signal and have their speeds controlled by the header. HOWEVER, that "Auto Mode Select" option in configuration of the CPU_FAN header is a PROBLEM here! The only unit sending its speed back to the header is the PUMP that we WANT to keep running at full speed. But the Auto Mode option will use that speed signal to DECIDE how to send out speed control signals, and it will decide that the connected load is a 3-pin fan that requires the older Voltage Control Mode signals to force that "fan" to slow down. Exactly the opposite of what is required for this particular installation! So the option must be set to PWM, not to Voltage or Auto.