I think the terms used here are a bit confused. Rather than saying that a road bike has 22 "gears", you should be saying that it has 22 "speeds" (or more correctly, as pointed out in the comments, "gear ratios" is the technically correct most accurate term (when people say 'gear', they are using it as short for 'gear ratios')).
Even that can be a bit confusing, but to figure out the number of "speeds" a bike has, you would multiply the the number of gears in the front (in the case of your bike, 3) by the number of gears in the back, (in the case of your bike, 8). Meaning that your bike is actually a 24 "speed" bike.
A typical road bike manufactured today might have 2 gears in the front, & 10 or 11 in the back - so a 20 or 22 speed bike.
For a mountain bike, 30 - 40 speeds is a bit of an exaggeration. Most mountain bikes will have 2 or 3 gears in the front & up to 10 or 11 in the back. The largest cassettes (gear set in the back) manufactured have 11 gears. So the max number of speeds (again, gear combinations) a bike can have would be 33 (3 in the front x 11 in the back), although this may be an uncommon combination.
Here is a photo of a 30 speed drive train.
Here is a photo of a 24 speed drive train.
Here is a photo of a 22 speed drive train.
Whether or not all of these gear combinations are actually practical to use is another question though.