This concept is also called “depth-of-field”. Your photo is two dimensional. Until 3-D technology progresses far beyond its current capabilities your picture will have height and width and that’s all. Depth is a concept we impose when we view that a flat photo is a representation of a scene from the real world where true 3-D does exist.
Depth-of-focus is a range of distance within your picture, in terms of depth, that is in sharp focus. Say you have a picture of a person and they are in sharp focus. The flower in front of them if a bit fuzzy and the building behind them is also somewhat unclear. You have succeeded in placing your subject within the range of sharp focus for the camera settings and light conditions at the time.
The ability to manipulate depth-of-focus is another tool you have to more strongly direct the viewer’s attention to your intended subject. A busy background can threaten to overwhelm your subject as they blend with the scene. Intentionally narrowing the depth of focus in your shot can convert the busy background scene into a broad swath of color that highlights and enhances your subject while tending to push them forward from the din of color.
Manipulating the depth-of-focus is all about aperture settings on your lens. A large opening such as F-2.8 will yield a narrow depth-of-focus while a small aperture such as F-22 will give a very wide depth-of-focus. If you want everything in the picture from a few inches to infinity to be in focus then use a small aperture.
Assuming your light source is not within your control, such as sunlight, then it is up to you to make all the right settings on the camera to get your desired result. Thinking in terms of proper light exposure, if you increase the aperture (Allowing more light to enter the lens) then you must also increase the shutter speed so that the exposure time is decreased. On a camera that provides manual settings there is no problem. It’s only a matter of practice. Your priority is to first set the aperture you need and then set the right shutter speed to make a good exposure.
With some “automatic” cameras you may be able to increase the shutter speed to force the camera’s light exposure logic to compensate by increasing the aperture to about what you need it to be. If you can do that then you can still manipulate depth-of-focus.