The overall width of hubs (known as OLD or "over locknut dimension") and the corresponding distance between the inner faces of the frame's rear dropouts varies depending on the number of cogs that were current when the bike was designed.
Old (pre-early 80's) frames, designed for 5-speed freewheels, had 120 mm OLD hubs. Later 6 and 7-speed frames/hubs had OLD's of 126 mm. Current 8,9 and 10-speed cassette hubs have OLD's of 130 mm for road bikes and 135 mm for mountain bikes.
6 and 7-speed cassettes fit on the same width freehub body with the 7-speed cogs closer together.
Shimano 8, 9 and 10-speed cassettes all fit on the same freehub body with the cogs being thinner and closer together as the number increases. For Campy, 8-speed is unique and 9 and 10-speeds fit on the same freehub.
Rims are kept centered between the lock nuts by "dishing" the wheel, that is the rim is made closer to the drive side hub flange. That is why the drive side spokes are tighter and more vertical than the non-drive side.