Most modern cartridges have a small PCB with 2 contacts on the one section of the unit, which contacts 2 contacts in the printer when inserted. The PCB has a small 1 wire EEPROM which has data like serial number, capacity and such in it, and the printer writes to it with each print ( isn't that 100 000 write cycle life of modern EEPROM nice for this) to have a remaining toner quantity. When it is down to the preset low level the printer will show the "Cartridge is getting low" display, and when it reaches a lower level an optical path through the toner reservoir ( a small clear plastic window and light guide, with a IR LED on the one end and a phototransistor on the other end, with a path in the cartridge that will only allow light through when it is nearly empty) will tell the printer the cartridge is empty. Take out, shake gently and put back and it will print another 100 pages till it is uncovered again.
This is for HP/Canon units, which are the most common ( used in many other printers as well, Canon is the largest supplier of laser engines in the world, so they have may other makes that use the Canon engine with OEM designed electronics and cases) and many are refillable, with you needing generally toner of the right type ( there are a few blends for different engines) and a new PCB to make the printer think you have put in a new cartridge.
Most of the printer driver updates serve no use other than to update the firmware so as to block the refilled cartridges, they are not bug fixes but DRM upgrades to make you buy "genuine part" toner cartridges ( at a massive markup). You will find that the box with the original cartridge comes with a preprinted and prepaid return label, so you return the used cartridge for "recycling", which is then that the OEM simply refills them, puts a new tear strip on and sells you a used cartridge at a new price.