The sharpest images have an f-stop of f5.6-f11
If you understand aperture, then you understand that the depth of field is determined by the f-stop. Wider apertures have a smaller depth of field where as smaller apertures have a greater depth of field. In theory stopping your lens down to the smallest aperture will give you the greatest depth of field.
But don’t confuse depth of field with sharpness. Depth of field determines what’s in focus, but not always how sharp the image can be.
Lenses often are designed around distortions, aberrations and other natural defects that are physically present when working with optics.
If you’re using a wide aperture (f2.8 for example), your image is subject to aberrations as well as possible lightfall off which causes vignetting in the image. Small apertures such as f16 start to become constrained by diffraction.
Every lens has a sweet spot. Typically this is the spot that balances these distortions and gives you the sharpest picture. On modern lenses (6 or 7 elements) this is typically any where from f5.6 to f8. With older lenses (4 elements) your sharpest image will be at f11.
But you should remember:
Depth of Field is not Sharpness and Sharpness is not necessarily a great image. Know the above and then only remember it when you need it. A great image is a great image regardless of the technical details.
If you don’t agree see the advice on blurry pictures.