Before Volkswagen popularized environmentally friendly diesel, the idea sounded like an oxymoron: How could diesel engines, which we so often associate with black plumes of pungent exhaust fumes, be green?

As we all know now, they couldn’t. For years, the automaker built its reputation on so-called green cars. But since 2015, when VW’s emissions cheating scandal surfaced, that reputation has been tarnished. And it’s not just the company’s reputation that has suffered. On January 11, federal prosecutors leveled criminal charges against six top executives for their roles in the scandal. This ordeal has been drawn out over more than a year, and strangely enough, it was only by chance that a team of researchers discovered that these allegedly green cars were in fact riding dirty.

So how did Volkswagen get away with cheating on emissions tests for so long, and how did they get caught? The answer lies in the way Volkswagen tweaked onboard electronics to make it so their polluting cars appeared to be producing normal levels of emissions. And they would’ve gotten away with it too, if it weren’t for those meddling scientists!

With the right technology, diesel-powered cars can indeed produce less carbon dioxide emissions than their gasoline-powered counterparts. In fact, under ideal conditions, both gasoline and diesel combustion will produce only water and carbon dioxide, says Gregory Thompson, a researcher at West Virginia University who was the chief author of the study that revealed something was not quite right with Volkswagen’s low-emissions diesel cars. “However, in the real world,” he adds, “we don’t have ideal combustion.” As a result, these cars also emit an array of harmful products including particulate matter, or soot, and nitrogen oxides, or NOx.

These contribute to respiratory irritation and acid rain. So how are exhaust gas emissions cleaned to acceptable levels — or not, in Volkswagen’s case?

At the heart of this scandal is a technology that is not directly related to emissions control, but plays an important role in emissions testing: auxiliary emissions control devices. These devices allow vehicles equipped with traction control to be tested on a chassis dynamometer, a sort of treadmill for your car that’s used to test emissions compliance. A dynamometer holds the vehicle stationary while the vehicle’s wheels spin on a rolling surface to simulate driving. In this situation, your car’s traction control thinks the car is unsuccessfully scrambling for grip. Its onboard computers respond by activating the brakes and other sensors to help control sliding. So auxiliary emissions control devices act as override mechanisms that can detect when cars equipped with traction control are on a dynamometer and not just stuck in the mud.

Volkswagen engineers cheated by modifying their cars’ auxiliary emissions control devices to do more than just override automatic braking, though: When a VW vehicle was on a dynamometer, its entire emissions control system switched over from a normal dirtier mode into a clean-running but much less fuel-efficient mode to fake its way to a clean test.

It was a complete accident that Thompson and his students ended up playing a key role in catching Volkswagen’s cheat. His research group had been contacted by the International Council on Clean Transportation, a nonprofit group whose mission is “to improve the environmental performance and energy efficiency of road, marine, and air transportation” by providing government regulators with research on transportation technologies. The ICCT asked Thompson and his team to study diesel passenger cars with the sophisticated mobile exhaust testing equipment his group had designed to test diesel exhaust during real-world driving.

exhaust testing setup in a VW
Gregory Thompson and his colleagues used sophisticated mobile testing equipment that allowed them to test the VWs without the cars' computers switching into diagnostic mode.

Thompson and his colleagues randomly chose two Volkswagen models and one BMW to test because they wanted to see results from passenger cars with different combinations of engines and emission controls. The two VWs piqued their engineering inquisitiveness because they had the same engine, but one had a lean NOx trap while the other used selective catalytic reduction, or SCR. “It was about finding some technologies we were personally interested in,” says Thompson. “It was totally random that we selected these three vehicles.”

Lean NOx traps and SCR devices are the two main types of emission-control devices used in diesel cars. While lean NOx traps collect NOx like a sponge collects water and grime before burning it off as water and nitrogen, the bulkier and older SCR devices work by injecting urea into the exhaust stream to convert the NOx into nitrogen and water. SCR-equipped cars need to carry an additional fluid reservoir that must be filled by the owner.

So why weren’t Thompson’s tests fooled, too? They key was that these tests were performed in real-world driving conditions, not on a dynamometer, so the VWs did not get the chance to switch into their clean mode.

At first, Thompson and his students thought the high levels of NOx and soot they found in the Volkswagens were faulty readings from their equipment. But the BMW’s numbers were within expected limits. “When we saw two vehicles were high and one was what we expected, we had pretty good confidence that the data was reflecting what was happening in the real world.”

Thompson’s team published its report in May of 2014, and it took a whole year after that for government regulators to take action. But take action they did.

In May of 2015, the California Air Research Board performed their own emissions tests and reported them to the EPA, who confronted Volkswagen with the evidence. Unable to provide a plausible explanation, VW confessed to knowingly cheating emissions tests. Their stock price plummeted. Their CEO resigned. German prosecutors initiated fraud investigations. Volkswagen has since been forced to allocate billions of dollars to fix vehicles that were equipped with chea devices. Their executives are facing criminal prosecution. And to think, this whole scandal broke just because some engineers in West Virginia were curious about diesel engines.

Photos via Thompson et al, Wikimedia user Thomas doerfer