Using the largest aperture such as F22 will render the best depth of field when needed but there is something just too good to be true. There is a negative trade off of diffraction when stopping down as far as possible. You can test thise yourself by placing your camera on a tripod and shooting at each aperture and zooming into your RAW files at 100 percent. Find a scene where the edges have enough detail. Corners will lose a subsequent amount of sharpness as you get closer to the largest aperture. We are taught to use the hyper focal technique to keep everything in the photograph tact sharp. The hyper focal technique consists of choosing the second largest aperture while finding the closest foreground compositional element and focusing twice the distance into the scene from your camera to the foreground element. In this case you would use the second smallest aperture. This works well as long as you are not too close to your foreground element. You can also try focusing a third of the way into the frame. Each focal length has a different requirement for this to work. Depending on how far your nearest foreground element is in the composition this will determine what aperture you use. The closer the aperture is to the lens's sweet spot the better the image quality will be. You will have to make the decision and keep the balance between the optimum image quality for your lens and the amount of depth of field. You can also bracket your images with differnt focal points to blend the exposures together using software like Helicon Focus. If your scenes has any moving elements like water, clouds, and foliage between exposures, the image will not blend together successfully. The photograph shown here is a case where a larger aperture was used to keep the balance between the sweet spot of the lens and the correct amount of depth of field. The corners of the frame are not filled with elements that are in need of crucial sharpness. Smaller image sensors like the aps size or 1.6 crop factor sensors are not as affected by lack of edge sharpness compared to large 35mm sensors. The results are better scene when printing large photographs.