Rear hubs vary in width (but most new ones are 130mm for road or 135mm for mountain). The hub width (over-locknut dimension) needs to match the space between the rear wheel dropouts in the frame in order for things to line up as they should.
120mm: 5 speed and "Ultra-6". An old hub size not used on new bikes.
126mm: 6 speed and some 7 speed.
130mm: 8 & 9 speed road.
135mm: Mountain 8 & 9 speed and some 7 speed.