As you can see, defining depth of field is a rather arbitrary affair. So how can you hope to control the results produced by your camera? Here is a range of options.
The rough guide
If you want an extensive depth of field, set a small lens aperture (higher f-number), such as f/16 or f/22. Using a small aperture may require a slow shutter speed for correct exposure, so use a tripod to reduce the effects of camera shake. Also, use a wide-angle lens for maximum effect.
If you want shallow depth of field, set a wide aperture (lower f-number), such as f/2.8 or f/4, and use a telephoto lens for maximum effect.
If depth of field is not a critical factor in your composition, use an aperture of around f/5.6, f/8 or f/11. Your lens will usually give optimum performance at these settings.
Basic modes
You might think that using one of the Basic mode settings available on EOS cameras would save you time and trouble. You might assume that the Landscape mode will give wide depth of field, while the Portrait mode will give an out-of-focus background. Unfortunately not. The Basic shooting modes are designed to give foolproof settings for beginners, avoiding the extremes of apertures or shutter speeds which give true creative control. The best advice for controlling depth of field while keeping things relatively simple is to shoot in Aperture priority (Av) mode.
Depth of Field preview and Focus Peaking
On a DSLR, the image you see in the viewfinder is normally the view at the largest aperture available on the lens you're using, meaning you can't visually assess the depth of field before taking a shot. However, if your camera has a Depth of Field Preview button then pressing this will stop down to the lens's current aperture setting, so you can see how much of the scene is in focus through the viewfinder and even more clearly on the Live View image on the LCD screen.
If your camera doesn't have a dedicated Depth of Field Preview button, you can assign this function to the camera's SET button with a custom function while using P, Tv, Av or M mode.
On the EOS 90D in Live View and on mirrorless cameras including the EOS R5, EOS R6, EOS R, EOS RP, EOS M6 Mark II and EOS M50 Mark II, you can also enable manual focus peaking (MF peaking), a visual aid to show which parts of the image are in sharpest focus. In theory, areas in focus will coincide with the greatest contrast, so the image is evaluated for contrast and these areas are highlighted on the display in a bright colour of your choice. You can see the highlighted areas of the scene change as you change the focus.
Hyperfocal distance focusing
Depth of field extends in front of the point of focus and behind it. In fact, apart from when the subject is very close, it extends roughly twice as far behind the focus point as it does in front. This means that if you focus at infinity or on the horizon you'll actually "waste" some depth of field and not get the widest sharp zone possible in your image.
Hyperfocal distance focusing is a technique that enables you to capture the maximum depth of field possible in a photograph. The aim is to focus so that the far limit of depth of field just reaches infinity (or the furthest point in the scene). The point on which you need to focus to achieve this is known as the hyperfocal distance.
The hyperfocal distance is the near limit of depth of field when you are focused on infinity. And when you focus on the hyperfocal distance, the depth of field extends from roughly half the hyperfocal distance to infinity.
There are depth of field tables widely available on the internet that tell you where the hyperfocal distance is for any given lens and camera combination, but hyperfocal distance is not a fixed value for a lens – it changes with the aperture and the focal length – so the easiest way to work it out is to use the depth of field and hyperfocal distance calculator in Canon's free Photo Companion app. You'll find this under Skills - Calculators. Then set your camera lens to manual focusing (there is an AF/MF switch on the side of most Canon lenses) and turn the focusing ring to this distance.
If you don't have time for calculations, a rough rule of thumb is to focus approximately one third of the way into a scene.