More than 40 beaches across Massachusetts are closed over the weekend, from Puffers Pond in Amherst to Washing Pond on Nantucket. Heavy rainfall is at the root of most beach closures, spurring on excessive levels of bacteria in the water and, in some cases, toxic cyanobacteria blooms that thrive in higher temperatures.

“The more it rains, the more stormwater runoff can pollute the water bodies,” said Marielena Lima, river sciences program manager at the Charles River Watershed Association.

The most common culprits are Enterococci and E. coli. Swimming in water that has registered a “ bacterial exceedance” can pose gastrointestinal and respiratory risks, as well as skin irritation and flu-like symptoms.

Rain can cause sanitary sewers to overflow and contaminants to intermingle with stormwater systems, bringing pathogens from sewage onto beaches. Residents who live near bodies of water can help prevent some bacterial contamination by picking up after their dogs to avoid spreading pathogens. And in cases of cyanobacterial blooms — toxic algal blooms caused by excess nutrients, like phosphorus, in the water and aggravated by high temperatures — residents should avoid using fertilizers that can run off into nearby lakes and ponds.

It’s likely that beach closures will become more common in Massachusetts. The state Department of Public Health tests over 1,100 beaches weekly to determine whether water is safe for swimming.

Robbie Goldstein, the state’s commissioner of public health, advised that beachgoers should check the department’s online map to make sure they’ll be able to get in the water.

“We should be anticipating that over the next few years, we’re likely to see the ongoing effect of climate change and the potential for more and more beaches to have to temporarily close,” Goldstein said.

So far, Goldstein said, bacteria levels haven’t been as high as last year, when flooding led to more widespread beach closures.

Environmental advocates are trying to raise awareness about the consequences of these bacterial blooms and what can be done to prevent runoff. In the Wrentham area, CRWA’s Love Your Lakes initiative focuses on ecological dangers of cyanobacterial blooms beyond beach closures, encouraging residents to rake leaves each fall and limit fertilizer use in order to protect marine species from low oxygen and acidification.

“Cyanobacteria can grow faster in these warmer temperatures and the extent of the blooms can be more intense or last longer,” Lima said.

An ongoing exhibit at the Museum of Science’s Yawkey Gallery invites guests to troubleshoot a germane dilemma: A snack bar with a sprawling parking lot is built near a river. Soon, an extreme precipitation event causes the water to become unswimmable. Visitors consider innovative flood control techniques in urban areas harshly affected by climate change, like the use of porous pavement around bodies of water.

David Sittenfeld, director of the Museum of Science’s Center for the Environment, pointed out that rising heats of course affect the people who live near those beaches, too.

“People are looking for ways — especially among the most vulnerable populations that are most at risk from the cascading hazards of extreme heat and extreme precipitation — they’re looking for ways to safely cool themselves down and it’s really important to get this right,” Sittenfeld said. “Having these beaches inaccessible to us serves as a kind of an exacerbator and a threat multiplier.”