If you've ever looked closely at a millipede, the answer is simple: most of their trunk segments carry two pairs of legs, and the number of segments increases as they moult and grow. That is why the legs seem to go on and on.
How millipedes grow so many legs
Millipedes are long, many-segmented arthropods with a body plan built from repeated sections. In many species, most of those trunk segments carry two pairs of legs each, rather than just one pair. The result is the dense, many-legged appearance that gives millipedes their name.
They do not hatch with their full adult leg count. As they grow, they moult and add more segments, which also adds more legs. A young millipede can therefore look quite different from a mature one, even though it is the same kind of animal.
If you want the numbers broken down more precisely, see How Many Legs Does a Millipede Actually Have?.
Why the topic matters
Millipedes are ground-dwelling detritivores, so their many legs suit a life spent moving through soil, leaf litter and decaying plant material. They are built for slow, steady movement in damp, sheltered places rather than for life on open surfaces.
That is useful to know when keeping them. A good setup usually gives them deep, moist substrate, leaf litter and hiding places. They often spend much of their time beneath the surface or tucked under wood and litter, and that is normal.
For the care implications, our Millipede Behaviour, Biology & Handling Guide is a useful starting point, and the wider Millipede Behaviour & Biology Guides cover more related topics.
Useful context
The name millipede does not mean exactly a thousand legs. It simply refers to a very large number, and the actual count varies by species and life stage.
If you want to understand how growth and moulting produce those extra segments, see What Is the Millipede Life Cycle?.
Millipedes are often seen less than expected because they are adapted to a concealed, litter-based habitat. That is part of their natural behaviour, not a problem.