It depends on the line. The more modern lines, have induction loops every 3 meters that allow precise measurement of current position, and also data for voice comms to the line controller.
On older lines, they can only detect when a tube changes power circuit and the resulting blue/white spark sends a measurable pulse down the power system. In this case, yes, they have to just count trains into and out of a section.
I learnt this by chatting to a TFL engineer in a pub, he designed the signalling systems equipment.