The number of legs that caterpillars can have varies with the kind of caterpillar and sometimes with its stage. Usually all of the butterflies or moths in the same family will have the same number of legs on their caterpillars, but this is not always the case. The caterpillars of some tiny leaf-mining moths may have no legs at all. Most caterpillars of the larger moths and butterflies have 3 pairs of true legs, and most have 5 pairs of prolegs on their abdomen. So the best answer would be that most often they have 16 legs.
This photograph clearly shows the 5 pairs of prolegs (to the left) and 3 pairs of true legs (to the right) on the Black Swallowtail caterpillar:
Black Swallowtail (Papilio polyxenes)