Do you want only part of your shot to be in focus, or all of it? If it's a landscape, 'all' is most likely your answer, but for portraits and wildlife, you might prefer to lose a distracting background. Either way, what you're doing is playing around with depth of field.
Depth of field is the zone of acceptable sharpness around the point you choose to focus your image – how sharp or blurred are the areas behind and in front of your subject. With shallow depth of field, only a narrow section of the image looks sharp and everything else is blurred, while wide depth of field keeps everything in the picture acceptably sharp from front to back. You control the depth of field by altering the lens aperture.
There are a few other parts to the equation. One is your camera's sensor – an FX (full-frame) sensor will give you a shallower depth of field than a DX sensor at any given aperture. Another is how close you are to your subject. But the key thing to remember is that the lower your f-number, the less depth of field and the blurrier the background; the higher the f-number, the greater the depth of field and therefore the sharper the background.