system
Given the following post, respond as if you're commenting on Reddit:
human
Eli5: how does my phone know how much percent of battery I have?
gpt
Almost all smart phones use two different methods together. 

The most simple is voltage. Voltage is not a very good indicator of charge in li-ion batteries used in phones because the voltage does not fall at an even rate when you use them. Voltage measurement is used as a fail safe. It's very bad for a battery's voltage to get too low. This is why sometimes when you get your phone cold in the winter it drops dramatically in charge percentage instantly. What has happened is the battery's voltage dropped when the phone got cold. Now the phone has started reporting an estimate based on voltage. 

The second and much more accurate is coulomb counting. This is like counting the individual electrons as they go in and out of the battery. It counts them as they go in (charging) and as they go out ( using it not plugged in). This allows the phone to know exactly how much energy it put in and can accurately guess how much is left. Just like putting gas In your car. The electronics that do this are actually called 'gas gauge' chips. 

The phone will have programming in it that will use both methods together to track and report charge state to you. 

Source : electronics engineer that designs things w li-ion batteries.