How does Windows know it's on battery power?

The laptop contains a battery management chip with SMBus, such as a BQ24721C.
This chip sits at the interconnect with the battery, charger and the system voltage regulator.
It handles detection of the charger and then manages the charging rate via an incorporated DC-DC controller. It also controls various transistors to disable or enable power from or to the battery, or from AC to the system.
These chips have various means to communicate with the rest of the system.
It has IRQs (interrupt requests), analog outputs, a power good signal and SMbus.

If the battery is replaceable, it will also contain some intelligence to measure battery status, and protect it. This uses SMbus or something proprietary. An example is a Coulomb Counter that measures the charge going in and out of the battery (eg: LTC2943)

SMbus is built on I2C; it's the "System Management Bus". All important stuff connects to this. For example it's also available on the PCI connectors.
It's loaded with small devices like fan controllers, temperature and ambient light sensors or simple switches and LEDs, like wi-fi on-off or lid closed.

Then it is up to the operating system drivers to know the layout of this bus, and how the devices work. Some of it is somewhat standardized in ACPI.


Check out the APM (Advanced Power Management) API and its successor ACPI (Advanced Configuration and Power Interface). Before APM these functions were handled by the BIOS.

For Windows 8 and later, Microsoft has these recommendations.

Hardware-wise it may be as simple as an I2C (two-wire) interface to a subsystem.


Aside from things like simple voltage sensors, it's absolutely not uncommon that you get integrating power meters that monitor the net power flowing out of a battery.

The question how these sensors talk to the OS is a different one, and will differ from model to model.

However, usually, the firmware in your laptop will talk to your sensors, process these values, and present them over a proprietary or standard interface (e.g. ACPI) to your OS.

PCIe is almost certainly not involved as main link – that's way too expensive to get a few bits every minute across. Electrically, expect I²C, variants like SMBUS, plain SPI, 3.3V UARTs, possibly USB, and all other kind of things with which you could connect a platform controller (which really is just a MCU) with sensors.