A flash hider does just that: it reduces the flash produced by the weapon so that the shooter is less visible in low light and (or) doesn’t get temporarily blinded by his own flash. A typical example is the A2 flash hider found on AR 15 rifles. There are many flash hider designs available, more or less effective
A compensator, as the name implies, “compensates” certain forces created when firing a gun. Specifically, it counteracts muzzle flip, caused by the fact that recoil works on a different line than that passing for the contact point between shooter and gun. Muzzle flip makes follow up shots difficult, as the shooter has to bring the gun down to bear before he can shoot again.
A compensator works by using part of the expanding gases escaping the muzzle so that they exert a downward push, partially or totally compensating (hence the name) muzzle flip. A classical example is the AKM slant cut compensator.
Another byproduct of firing a gun which is quite relevant to the shooter is recoil. Recoil can be anything from annoying to downright painful and may even cause injury.
A muzzle brake is a device, that uses part of the forward moving gases expelled by the gun to actually pull the gun forward contrasting recoil, like an inverted rocket engine of sorts. On a small bore weapon like a pistol or assault rifle, it allows for a more stable shooting platform for faster follow up shots. On big caliber guns, such as 500 S&W “hand cannons”, dangerous game rifles or long range sniper rifles, it lessens recoil to a manageable level.
The muzzle brake on the Barrett M82 sniper rifle is a perfect example.
The main disadvantage of a muzzle brake is that it diverts most of the hot gases energy sideways and backwards, so that sound level perceived by the shooter or nearby people is highly increased (most of the sound energy of a gunshot is directed forward, unless we divert it somehow).
Actually, most muzzle devices perform all these functions together to varying degrees. The A2 flash hider also works in part as a compensator, and the M82 muzzle brake acts also (partially) as flash hider.
Most compensators act as muzzle brakes as well. Some devices, like the Noveske KX3, work as flash hider and direct the sound of the gunshot towards the target, instead than sideways and back to the shooter.
They are useful with short barrelled carbines in tactical situations where gunshot noise can be painful or even dazzle a buddy while clearing a room or in other CQB situations.
They are not “silencers”, they just divert gunshot blast forward, and do not compensate muzzle flip nor they reduce recoil, if not by the weight they add at the end of the barrel.
All these are useful devices but, as we said, anything that perturbs the gases as they exit the barrel and rush past the bullet (hot gases produced by powder combustion have a far higher exit velocity than the bullet itself, due to their expansion in open air) has a chance of perturbing bullet motion and reducing the intrinsical accuracy of the gun.
There are some exceptions, though: some highly accurate competition airguns use a sort of compensator to insure uniform gas expansion away from the pellet, so that it is left as undisturbed as possible in its flight. Some hunting rifles have adjustable muzzle brakes that can be screwed closer or farther from the muzzle: this shifting of weight actually “tunes” the comparatively thin hunting barrel vibrations to the specific cartridge used so that the muzzle is as stable as possible when the bullet leaves the barrel, which is the most critical moment as it comes to accuracy, second only to it entering the forcing cone.
Muzzle brakes/compensators may also be useful: even if they reduce theoretical accuracy of the gun when fired from a rest, they can dramatically improve practical accuracy of a hand held or shouldered gun by making it more stable, or by making usable a weapon whose recoil would be otherwise unmanageable.
So: are muzzle devices as detrimental to accuracy as it is commonly believed? It all depends on the circumstances and on what kind of use the gun is meant for.