Just curious to understand, what does a mobile battery percentage indicate?
What is the input and output in the percentage formula with respect to batteries?
Unlike the fuel tank of a car which has a simple physical parameter, the volume of fuel, a battery's voltage does not fall linearly with the amount of charge left in the battery. In fact a lot of effort goes into trying to make the battery voltage remain constant until it is close to fully discharged.
Figure 1. A randomly chosen battery discharge curve. Source: Uncredited on Estimating Li-Ion (or any other type) battery resistance.
Note that the vertical axis on the graph does not start at zero.
To give an indication of the state of charge phones have a charge controller built-in. (The so-called "charger" is just a power-supply and doesn't contain a charge controlling circuit.) The charge controller will monitor the battery voltage during charge while keeping an eye on temperature. When the voltage rises to a preset level the battery is deemed fully charged.
In use the charge controller can "count" the amount of charge used while again monitoring the battery voltage and temperature. When the voltage drops to the lowest limit it will know the capacity of the battery (which will deteriorate with each charge / discharge cycle).
After that it depends on the hardware of the charge controller or the software of the phone. You can expect some fudging of the remaining charge level with the aim to give you the appearance of an accurate readout - "It's digital so it must be accurate?" - Not really. Batteries are analogue.
From the comments:
But when you say, "Note that the vertical axis on the graph does not start at zero", what is the inference that one should draw?
You should realise that the graph is flatter than it appears. If you take the green curve the battery gives out 4.0 V at full charge. We can see that the voltage starts to collapse at 3000 mAh (empty) so if we take 1500 mAh as "half full" we can see that the voltage is still about 3.5 V. If it behaved like a fuel tank it would only be 2.0 V.
When you say, "In fact a lot of effort goes into trying to make the battery voltage remain constant until it is close to fully discharged" - Even after prolonged use of the battery, the charges depletes but the voltage should remain constant or near to the original voltage before we started using it?
Yes. Most electronics are designed to run on a specified voltage so a constant voltage power supply (battery in this case) is desirable.
Does the voltage on the vertical axis never go to 0 V?
No, it will if you continue to discharge it. Many battery chemistries are damaged or severely degraded if you completely discharge it. Your phone battery management should power down the phone before this happens. This may happen at 3.0 V or whatever the manufacturer decides.
Does that mean, a battery will never go to 0 V but will stay at 2.5 V at worst case when depleted?
If it stayed at 2.5 V then it would be an infinite power source. The graph shows what will happen but doesn't go below 2.5 V because you shouldn't ever be in that region.
Most likely voltage.
Whenever a battery discharges its voltage reduces. If your phone's battery has a nominal of 3.7 volts this means that fully charged it will have 4.2V and fully discharged about 2.5V
Now you can monitor the voltage and determine the percentage of charge with a simple formula like the following:
(Current voltage - Discharged voltage) / (Charged voltage - Discharged voltage)
Which is still dependent on the discharge characteristics of the battery but is a general simplification.