How Your Phone Knows Its Battery Percentage

Have you ever stopped to wonder how your phone knows what is going on inside a sealed chemical pouch?