Here's the deal. Inside the muffler is glowing hot after running at high RPM. When you shut down the engine, it is spinning down with no ignition and it still continues to draw fuel from the carburator and exhausts the unburnt fuel vapor into the muffler which to an extent cools things a bit. When the engine is still, the heat in muffler heats & ignites the residual fuel vapor and causes the backfire.
Now, there are two issues at hand for preventing the back fire.
If you have an older engine (Kohler Magnum for example) without a high speed circuit/fuel shutoff solinoid screwed into the bottom of the carburator float bowl (has single wire) then the best bet is to allow the engine to idle for two minutes or longer to cool the exhaust and then shut it off.
If you have a newer engine (Kohler Command for example) with a fuel solinoid in the float bowl, then you are supposed to shut these off at Full Throttle. The Solinoid closes off the high speed circuit fuel flow when the key is turned off stopping the flow of fuel. As the engine spins down, the exhaust is purged of fuel vapor by a very lean fuel/air mix.
If you shut down at idle speeds, the idle circuit in the carb is active and dumps fuel into the exhaust even thought the high speed circuit is inactive.
All that being said, there are some dumb ass manufacturers that couldn't wire a flashlight and subsiquently there are a number of engines wired such that when they are shut off, the DC voltage from the charging system backfeeds into the wiring keeping the fuel solinoid open until the engine spins down (remember, the alternator is under the flywheel) thus causing a backfire no matter what. The wiring can be modified or a different ignition switch can be used to eliminate the problem.