Since this is ELI5; they measure the number of electrons flowing in and out of a battery. Analogous to a pump counting the gallons of liquid going in to a an empty tank and then counting the gallons of liquid coming out of it. Difference gives you what remains. Design capacity is programmed and set. Zero is set when nothing comes out of it (full discharge). Current (as in present) capacity is when nothing goes in (full charge).
As to how the electrons going in and out are measured, thats done by placing a resistor in line and measuring the voltage drop across that known resistor. Ohms law then gives you the current. Same principle as an orifice type flow meter.
Latest Answers