For some Lowell residents, a rainstorm in the forecast used to mean they would see sewage backed up in their basements.

For others, the Merrimack River could become too contaminated with bacteria to swim in for days.

That’s because smaller and older sewer pipes in some neighborhoods couldn’t handle sudden outflow from catch basins. The rainwater surging through sewer pipes would also overwhelm the treatment plant, causing raw sewage to flow into the river.

But raw sewage floods into the river much less frequently now that the city has spent $80 million to install new pipes that bring rainwater straight from catch basins to the river. That effort by Lowell, along with the investments other communities along the Merrimack River have made to improve their sewer systems, may be paying off, helping to keep the river cleaner than ever, according to environmental advocates.

“It looks like it’s potentially making some improvements,” Merrimack River Watershed Council Executive Director Caroly Shumway said of the results of the organization’s river water testing.

Shumway credits the sewer projects across the region as the potential control factor.

The recently released MRWC data shows that the bacteria counts in the river between Nashua and Lowell have been declining since 2009 and 2010, depending on the location.

The Lawrence-based nonprofit agency has taken water samples monthly from different locations in the river to monitor E. coli counts against the state standard of 235 colonies per 100 milliliters of freshwater — the level over which the Environmental Protection Agency recommends that a beach be closed. In 2008, bacteria counts exceeded the state standard at two of four Lowell sampling locations, each just once. But those figures were far in excess of the standard, showing well over 1,000 colonies per 100 ml.

In 2011, all four locations had more E. coli than allowed, and one of the sites exceeded the EPA standard twice that year. However, the counts were less than 400 colonies per 100 ml.

New Hampshire has a stricter E. coli standard of 88 colonies per 100 ml. In 2010, water samples taken from Nashua sections of the river had nearly 400 colonies per 100 ml on average in June, and more than 250 in July. But no samples exceeded the state standard in 2011.

Mark Young, executive director of Lowell Regional Wastewater Utility, said Lowell has installed 16 miles of rainwater-only sewer lines so far, and much of the work was done in late 2008 through 2009.

In old mill cities, such as Lowell, Lawrence, Haverhill, and Manchester and Nashua, N.H., both wastewater and storm water go into the same sewer pipes connected to treatment plants. The EPA has required those communities to separate storm water from regular sewer water because heavy rainfall causes sewage volume to exceed treatment plants’ capacities, causing wastewater to flow into rivers untreated.

In Lowell, a quarter-inch rainfall used to guarantee an overflow, Young said.

“We cut the number by well over half,” Young said of the inch count.

Nashua has earmarked $72.29 million to deal with its combined-sewer-overflow problems, and about half of the project was completed by the end of 2009, including the construction of a second wastewater treatment facility to handle increased sewage volume during heavy rainfall.

Tyngsboro does not have a combined-sewer system, but what floats down from Nashua influences the quality of the river water, according to Allen Curseaden, the town’s sewer superintendent.

In August and September 2008, water samples that MRWC took from Tyngsboro sections of the river contained more than 400 colonies and nearly 1,000 colonies per 100 ml, respectively. But no samples exceeded the EPA standard in 2009, and E. coli counts have since remained between zero and 50 colonies per 100 ml except for occasional upticks, including June 2010 and July 2011, when the bacterial levels hovered around the EPA standard.

In the meantime, the E. coli counts in sections of the Merrimack in Lawrence and Haverhill have risen in recent years, logging between 400 and 600 colonies 100 ml during some summer months last year.

Bob Ward, deputy director of the Haverhill Department of Public Works, said the city spent about $20 million before the end of 2006 to increase the capacity of its existing sewer treatment plant so that less sewage would overflow during heavy rainfalls. The city submitted its longer-range plan to deal with the combined-sewer overflow with the EPA in 2011, but has not acted on it yet.

The second phase would again involve the expansion of the treatment facility’s capacity. The city will not install rainwater-only sewer lines after weighing the cost and the environmental benefits the money could buy, Ward said.

Lowell’s Young said tributary waterways into which E. coli streams from septic systems also contribute to the bacteria counts in the Merrimack River.

Bird feces, which contains E. coli, also push up bacteria readings in certain locations where people feed birds, such as near the Bellegarde Boathouse in Lowell, Shumway said.

EPA has a plan to address those contributing factors, including dog waste in people’s backyards, to help keep rivers clean, she said.

To see the E. coli and other data, visit http://www.merrimack.org.

Follow Hiroko Sato on Twitter, @SatoLowellSun.