Choosing the f-stop or best aperture is a main determining factor about what is in focus when you photograph an image. The length of the camera lens and the distance you are from the subject also are factors.
In general, when you are photographing one or two people for a portrait, you want to use an aperture setting of f-4 or f-5.6. This will give you enough depth to make sure the heads are in focus and the foreground (the area in front of your subjects) and the background (the area behind your subjects) is a bit out of focus so it doesn’t distract the eye from the faces of your subject.
When you are photographing a group of more than two people, you want to use a deeper depth of field, so I would use a smaller aperture setting of f-8 to f-11 for a group that has two rows, and increase the f-number as the depth of the group increases. Remember, the higher the F-number, the smaller the opening and the more depth of focus.
When you are photographing a landscape, you may want to use an aperture of f-22 or above so that the whole scene is in focus.
When you photograph a flower, you might want to use f-4 or below so that the flower is the only thing in focus. With f2.8, you will have to carefully weigh your subject and what you want in focus because your depth of field is only inches wide. What isn’t in that area (in front and in back) will be out of focus and sometimes it is part of your subject.