A cars engine will backfire when the fuel and air mixture is not correct and that causes the fuel to not be burnt properly so you get the engine backfire.
You could be getting either too much fuel or not enough spark to the cylinder to burn the fuel properly which results in a backfire.
When your car is losing fire and backfiring there could be several causes such as low engine compression, clogged fuel filter, dirty air filter, clogged Exhaust Manifold.
Other causes of engine backfire and loss of engine power are Bad fuel injectors, bad fuel pump, bad spark plugs bad ignition coils, bad spark plug wires etc.
Usually though when the engine backfires it's caused by not enough spark due to bad ignition coil or bad spark plugs.
If you haven't replaced the spark plugs or ignition coils within 100,000 or more miles then it would be best to replace them.