FYI All questions

How does a phone know its battery percentage?

It estimates charge from voltage, current flow, temperature, battery chemistry, and learned usage. The number is a model, which is why it can occasionally jump.