A lens is not a perfect device. Whilst computer aided design has helped improve the image quality from lenses using such techniques as aspheric elements, a lens is still limited by physics and the behaviour of light.
One of the key limitations is diffraction. When light passes through a hole, the light rays that pass very close to the edges of the hole are bent as they exit the hole. This bending causes a loss of sharpness of the image. The smaller the hole, the more this effect is apparent.
From a sharpness perspective, the optimum aperture of a lens is generally two stops down from its maximum – typically around f/8.
As you approach narrow apertures such as f/22 and beyond, the loss of sharpness can be noticeable at larger image reproduction sizes.
The larger your sensor/film the less noticeable this effect is, because when you capture an image with a large film size your magnification ration is much higher than for a small sensor. For example lets say I capture a 1.8m person on a 35mm film plane and they are rendered as 1.8cm tall. If I take the same image from the same camera location using a 4×5 large format camera, and use an appropriate lens to fill a similar proportion of the film area, the person will be rendered as 7.5cm tall. Thus there is significantly more detail recorded on the larger film format, so a loss of sharpness from a small aperture is much less noticeable.
This is why the ‘f/64 group’ that Ansel Adams was a member of exposed the use of very small apertures. They were using 4×5 or 8×10 cameras, and because the magnifications were so much larger than a 35mm camera they needed to use much smaller apertures to achieve a reasonable DOF. This is also why many 35mm lenses do not have these small apertures of f/45, and f/64.
So the moral of the story is: only use these small apertures (f/22 and beyond) on 35mm sensors if you know that your reproduction sizes will not be very large.