What is a backfire?
A backfire is what happens when unburned fuel which is not in the engine explodes. Technically, a backfire is an explosion before the ignition chamber of the engine (when the exploding gas moves back through the fuel injection system), but the term is used for after-fire as well, when unburned fuel makes it through the engine and explodes in the exhaust system. It produces a loud bang and a flash of fire from the exhaust. The latter is far more common, and since they produce the same noise they get called the same thing, and I'm going to assume that the average crime fiction author uses 'backfire' for both issues.
In the normal operation of an engine, the explosion inside the piston does not necessarily consume all of the fuel that is inside the firing chamber, and some of it continues through to the exhaust where it can build up. Normally, due to the timings of the pistons, this very small amount of leftover fuel burns in the exhaust system at regular intervals and produces a moderately loud rumbling sound. In small engines designed to be fuel efficient, this doesn't happen. Many supercars and muscle cars are designed to let this happen by dumping more fuel than is actually needed into the engine to induce after-fire and produce a satisfying noise and spit of flame when the engine revs, even though it is bad for fuel efficiency. It can also happen under sudden braking because fuel isn't being burned but is still pumped through the engine, goes to the exhaust, and explodes. Most backfires aren't that loud, and are an intended part of how a car works.
Aside from acceleration and braking of high performance cars, some part of the process may malfunction in such a way that fuel ends up either before or after the ignition chamber in dangerous quantities. This is where the really loud backfires occur. It could be for many reasons, such as a malfunctioning spark plug, a fault in the fuel injector system, or stuck valves. Whatever the mechanical cause, the result is that an unusually large amount of fuel builds up and explodes, producing an especially loud bang.
How common was it and when did it stop being a thing cars did?
Backfiring has been an issue since the invention of the internal combustion engine, and was rife in the first cars. In many early cars, such as the Model T, ignition timing was controlled by the driver using a lever on the steering column which would make the spark plugs trigger at different rates. To travel faster requires more fuel and more explosions in the pistons, which requires the spark plugs to trigger more frequently. Failing to match the spark plug timing to any given speed could result in fuel either building up before or after the ignition chamber. As you can hear in this clip of a Ford Model A being driven by someone who doesn't understand what the ignition timing lever is, it could make backfiring pretty much constant. For crime novels set in the early 20th century, there was no shortage of backfiring cars. As you can hear toward the end of that clip, the explosions could definitely sound like gunshots from a distance.
Automating ignition timing made backfires less common, and as methods of more accurately controlling that process have improved, along with general improvements in manufacturing standards, the odds of mistimed ignition or a malfunction have gone down. With the development of electronic engine management systems in the 1980s, they became rarer. Another important change was the move from carburettors, which build up fuel before the engine which could lead to backfires, toward fuel injection. With mechanical ignition timing and carburettors a thing of the past by the end of the 90s, misfires are rare outside of cars that are either very old or very broken. As you are 41, you were just in time for this shift in car design so it's not surprising that you've never heard a serious backfire. I only know what they sound like thanks to one of my colleagues who drives a beaten up MG Midget from the 60s.
Was it really that easily mistaken for a gunshot?
A backfire and a gunshot are, in terms of what happens with the expanding gases, very similar. In both cases, rapidly expanding gas is pushed out of a tube, at which point it moves out from the end as a shockwave. With a bit of distance, a gunshot and a backfire can become indistinguishable. It fools people to this day..
The sound of a car backfiring is actually very similar to the sound of a single gunshot. A quick search on YouTube will confirm this for you. — A car or motorcycle will backfire when some of the gas that is injected into the cylinder remains unburnt and it shoots into the exhaust pipe, where the very hot exhaust pipe ignites this gas and air mixture in the exhaust pipe creating a loud bang. This happened much more often with older cars that had either carburetors or partially computer controlled ignition systems. Newer cars where every component of fuel delivery and ignition timing is controlled by computer very precisely, rarely has any unburnt fuel at the end of the ignition cycle, and therefore rarely produces a backfire. — Some modern cars, like the Mercedes SL65, and some muscle or show cars are designed to purposefully eject a little unburnt fuel after hard acceleration, giving a gratifying cackling sound that is often associated with muscle cars, but that does not sound like a traditional backfire.