Flash photography can be a challenge, mostly because it is the intersection of your camera mode and the flash modes. This will be in Canon-speak, but most camera systems are similar, using different names and acronyms.
On Canon cameras, you have Manual (M), Program (P), Aperture Priority (Av) and Shutter Priority (Tv). The Canon flash system communicates with the camera, so the flash knows the camera mode and settings. The flash also has its own modes: TTL and Manual. TTL uses info from the camera, and a ‘test flash’ to determine subject distance and exposure and automatically determines the amount of flash to provide. In Manual mode, the user sets the amount of flash.
It is likely you have your flash in TTL mode since you do not mention otherwise.
In Manual mode on Canon, using TTL, you set the aperture and exposure, and the flash responds with the appropriate amount of flash. When you push the shutter button, the flash sends out a pre-flash, which it uses to measure the scene, then adjusts the power of the ‘real’ flash. This happens so fast you don’t notice it.
So, if you stand closer or further away, the flash will respond by adjusting the power to get the exposure correct based on the pre-flash. If you put the flash in Manual mode, you can set the flash to constant power, rather than this variable power.
If you put the Camera in Program mode, the camera will always try to maintain high enough shutter speed to keep a photo sharp. But when you attach a flash, the camera has to make assumptions about how you want to use the flash: it the scene is fairly bright, it will assume you want to fill the foreground but not at the expense of the background exposure, so it will adjust the flash power to do fill only. If the scene is dark, it will assume you want to light the foreground, and will adjust the power to light the foreground at the expense of the background.
If you put the Camera in Av or Tv, the flash always works in fill mode, because the camera is holding either aperture or shutter speed, respectively. It will also work to ensure that you do not exceed the flash sync speed, and flash in the viewfinder to tell you when you get above the sync speed (depending on your camera and flash models).
So, the modes are tricky, and Manual is not always ‘best’. My advice it to choose the camera mode that best fits your scene and subject.