Most modern handguns and rifles ship with their factory sights set pretty close to perfect. However, everyone's eyes are unique and different types of ammo can land in varying spots around the point of aim. Also, many AR platform rifles don't ship with iron sights at all, letting the buyer add whatever type they want.
Whatever the cause, you might need to adjust your handgun or rifle sights to get your ammo to land precisely where you expect based on the aiming point.
Depending on the type of gun, you may be able to adjust either the front or rear sight, or you might have to make adjustments to both. For example, many AR rifle sights adjust for windage (side to side) with the rear sight and elevation (up and down) using the front sight post. Older guns like "cowboy" lever action rifles are exactly the opposite.
Once you know how your sights operate and adjust, you'll need to understand how adjustments of both front and rear sights work.
When adjusting a rear sight, you move it in the direction that you want the next shot to go. When adjusting the front sight, you'll need to move it in the opposite direction of your desired point of impact.