Powder does not contain enough oxygen to burn all the propellant. So propellant is always expelled at the muzzle. Might be a solid, might be in gas form. If gas, it sometimes ignites when it hits the air (oxygen). This flash is a foot or so in front of the muzzle. It might also produce an extra loud bark of its own.
Some powders (most) contain additives to reduce muzzle flash. Some to a better job then others.
Muzzle flash has nothing to do with un-burned powder or lost energy.
This is exactly what is happening.
With very few exceptions, most pastes are formulated with a slightly negative oxygen balance. The flash is produced from the super heated gases coming into contact with oxygenated air.
When manufacturing detonating formulations I keep as close to neutral ( balanced) or slightly positive.
A variation of sodium is sometimes added in small amounts to either the paste or to a surface coat as a deterrent to reduce flash. In higher ratios it will directly affect the VOD's