I have a Nikon D-5300 with 18-140mm zoom lens, Recently I visited a place, where I wanted to capture the mountain and lakes with the subject. As a beginner I used to click in Auto mode. I was able to focus the subject and making the background in blur and vice versa with auto mode. Is there any way, so I can get a clear back ground as well. Thanks
A possibility is to put your camera in an 'aperture priority' mode, which is some form of auto mode with the exception that you are in charge of the aperture. (Aperture influences the depth of field, causing blurry foregrounds/backgrounds) Once in that mode you can close down the aperture (increasing the number). By closing down you allow the dept of field to increase, and in that case getting more of your view in focus.
Some notes to keep in mind: when you are at the wide end of your lens (18mm) and you focus on the subject in front of the mountain using a smal aperture, you are more likely to have everything in focus. When using the telephoto end of your lens (140mm) and focus on the subject, chances are only the subject and nearby object might be in focus due to the compression cause by the telephoto propertie (but that is another topic).
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.