How is state-of-charge measured for Li-ion batteries?

My 2-year-old cell phone is going nutty with regard to battery charge level. the reported state of charge sometimes drops suddenly from well over 50% to 1%. That’s when I catch it, anyway. If I don’t catch it, then the phone will shut itself down, presumably because it thinks the battery is completely empty. When I start it up again, it’ll report a reasonable state of charge, something like what it should be for that time of day.

So what’s happening in there? How is the state of charge measured on a Li-ion battery in the first place? Why might it be getting flaky?

It depends on the battery management chip.
Most modern ICs do “coulomb counting” - they measure the charge and discharge power and figure out the power remaining in the pack from that. But, if the battery is going bad, the IC may do a bad job of estimating the charge remaining.

The state of charge is also calculated based on the “voltage discharge curve”. If it is dropping off quickly that is typically a sign of old age and that the build in functions that calculate the capacity are no longer valid.

figure 2 in this link will show how most basic terms are calculated and it can be a simple mapping of voltage to percentage charge in many cases.