It's all about depth of field. That's the distance range from your camera where subjects will be reasonably in focus.
Depth of field is a function of aperture. The more wide open (lower f-number) the lens is set to, the shallower the depth of field. For example, you get more of the scene in focus at f/22 than you do at f/4.
Some lenses, particularly old manual-focus and manual-aperture ones, come with a scale showing you what will be in focus. There is usually a pair of lines for a few choice f-stops. These are fixed to the lens body, and match up to points on the focus ring as that is moved. The two lines for the current f-stop show you the distance range on the focus ring that will be in focus.
This leads to something called the hyperfocal distance. Let's say you want to take a picture of a mountain in the background with as much of the near foreground in focus as possible. First, you use the highest f-stop you can tolerate for other reasons. Then you set the focus to the hyperfocal distance for that f-stop. That means the center focus is a bit in front of infinity. The hyperfocal distance is where you set the focus so that infinity is just at the far end of the depth of field. That leaves the near end of the depth of field as close as possible while still keeping the background in focus.
There is another competing effect that eventually gets you at small apertures. That effect is diffraction. Things like the f-stop diaphragm are intended to cast a hard shadow. Light rays either go straight thru or get blocked. However, light rays very close to the edge are actually bent around that edge a little. This happens over distances about the wavelength of the light, so we don't usually notice this on a human scale.
This happens all the time at the edges of the aperture diaphragm in the lens, regardless of what the aperture is set to. However, at small aperture, the thin ring of area around the edge where diffraction is significant is a much larger fraction of the overall area. When a large enough portion of the light rays don't go straight when passing thru aperture anymore, the image appears unsharp and can also look hazy if there are some bright areas, even if off-picture.
For most ordinary uses, you won't notice this effect except at particularly small apertures, like are common on macro lenses.