The term backfire is often applied to two different "pop" sounds that the engine makes.
An engine can backfire through the carburetor. This will happen if something manages to ignite the air/fuel mixture as it is being drawn into the cylinder. On a four stroke this will result in flame shooting back out the carburetor. On a two stroke the reeds generally block it ends up sounding more like an "umph" than a bang.
A backfire out the exhaust is generally the result of the engine failing to ignite the air/fuel mixture for several revolutions. The air/fuel mixture passes through, filling the exhaust system with a burnable mixture. Then the cylinder does fire and it ignites all the fuel in the exhaust.
Conditions that can lead to backfiring include:
Poor ignition or fouled plug.
Ignition timing being way off.
Too lean or too rich of a mixture