If you want everything in the picture to be in focus, you want a tiny aperture, which has a large f-stop number.
If you want only the subject to be in focus and everything else somewhat out of focus, you want a large aperture, which has a small f-stop number.
Once you've settled on your aperture setting, adjust shutter speed to set the exposure. But the slower the shutter speed, the more motion blur you will get as your subject moves.
So you have to make tradeoffs. If you don't want your subject to be blurry due to motion, you need a fast shutter speed and the consequence of a fast shutter speed is that less light reaches the sensor, so you need to open up the aperture.
You have to make a choice between depth of field by setting the f-stop (what ranges are in focus in the image) and image blur due to motion by setting shutter speed. You have a large range of possible choices. As long as you get enough light for a good exposure.
You will want to learn about your camera's metering mode. Once you learn to use the meter, you will always be able to choose your f-stop or your shutter speed and use the meter to make the other adjustment to get a good exposure.
Google "Nikon D5100 metering mode" and you'll find some good information that will help you quickly.
Once you've learned how to use the meter, set up your camera on a tripod (assuming you have one) and take the same photo of the same thing, at every possible aperture setting, and adjusting shutter speed from the meter reading. Then review the pictures and see how the different aperture settings change the quality of the focus.