This question is just one of curiosity. I have a hard time visualizing this. How do internal hubs work? Does anyone have a cross cut image that is easy to understand?
The only scheme I know of is called planetary gears, or as Wikipedia calls it Epicyclic gearing. @Daniel suggests that there are other designs.
Here is one of the images from Wikipedia:
The inner gear is called the sun and the gears that go around that are called the planetary gears. In the basic design (the original Sturmey Archer design) the sun was fixed to the axle, and the pedals could either drive the assembly that the planets are on, or the outer ring. The wheel could be driven by the outer ring or the planetary assembly. A moving selector device controls the mechanism. The gear ratios were 1:2/3, 1:1, 1:3/2.
Thanks to @RoboKaren for editing in the image.