Tainted tap water isn’t just a problem in Flint, Michigan. In any given year from 1982 to 2015, somewhere between 9 million and 45 million Americans got their drinking water from a source that was in violation of the Safe Drinking Water Act, according to a new study. Most at risk: people who live in rural, low-income areas.

In general, “the U.S. has really safe water,” says Maura Allaire, a water economist at the University of California, Irvine, and lead author of the new study. Still, problems with drinking water crop up every year, and in some municipalities, year after year. The contaminants in the water can cause stomach flu or “more chronic conditions including a variety of cancers and neurological disorders,” she says.

Allaire lived near Flint in 2015, when the city’s water crisis captured the nation’s attention. That made her wonder: “How widespread a problem is this across the country?” She couldn’t find a satisfying answer. For more than 3 decades, the U.S. Environmental Protection Agency (EPA) had been compiling information about water quality violations across the country—but no one had published a national assessment looking at long-term trends in those data. So she took it on herself.

Allaire and her colleagues downloaded EPA’s data and looked at the number of health-related water quality violations for 17,900 community water systems in the continental United States over a 34-year period. Some were for elevated lead levels, the problem in Flint, but the data set also included violations for coliform bacteria—a group of microbes that is easy to detect and serves as an indicator of bacterial contamination in general—nitrates, arsenic, and other contaminants. The researchers combined those data with information from the U.S. census such as housing density and average household income, to figure out which communities were most vulnerable.

They found that during the Flint water crisis in 2015, nearly 21 million Americans—about 6%—were getting water from systems that violated health standards. And looking back over time, the number of violations generally increased from 1982 to 2015—spiking in the years following the addition of a new regulation, the team reports today in the Proceedings of the National Academy of Sciences. For instance, after a rule about coliform bacteria was enacted in 1990, the number of violations doubled within 5 years. Such spikes don’t mean that the water suddenly got worse, Allaire says, just that previously accepted levels of a contaminant were now considered too high.

County-level water quality violations per water system, 1982–2015

Violations of health-related drinking water standards were more common in rural counties. Click or hover over each county for more details; data were not available for counties in white.

At the bottom of the pack were Washington, D.C., Oklahoma, Idaho, and Nebraska. In the latter three, more than a third of water systems had violations in multiple years. And when the researchers looked at what counties were most vulnerable, they found that low-income, rural counties were the hardest hit, especially in Oklahoma and in parts of Texas and Idaho. Small water systems can’t afford the latest and best treatment technology, and sometimes they can’t even afford a full-time operator, Allaire says. “So they’re struggling.” But there was a silver lining: Small communities that purchased treated water from larger utilities—especially privately owned ones—had fewer violations. (EPA declined to comment on the new study.)

When treating water, some communities are dealt a bad hand to start with because of dirty source water—especially in southern states such as Oklahoma and Texas, where hot summer temperatures create an ideal breeding ground for bacteria. That’s why it’s important to prevent contaminants from getting into the source water in the first place, for instance by installing wood chip bioreactors on farms to reduce nitrates in runoff water, says Michelle Soupir, a water quality engineer at Iowa State University in Ames. We’d “have a better, safer drinking water supply and take some of the burden off the water treatment.”

Another idea is to merge “teeny water systems” with larger systems, says Erik Olson, a policy expert at the Natural Resources Defense Council in Washington, D.C. We can’t have these rural providers “continuing to serve bad water,” he says.