Q: I live in a townhouse in Gaithersburg, Maryland, built in the early 1980s. It has a finished basement with a small egress window with a rounded well outside. During heavy rainstorms, which we had many of this summer, this well fills with water and leaks through the window, even after I replaced it. I have a plastic cover over the well and even have large bins around it to try to divert water, but at a certain point when the ground is saturated, the well begins to fill from the bottom. I have to physically bail out the water, usually as rain is pouring down around me. I’ve had to replace the basement drywall twice because of mold, and I got rid of the carpet. Is there a solution to this problem?

A: Even decades ago, when builders installed window wells, they usually took care to deal with underground water. “Typically window wells have a drain that is connected to the foundation drainage system or drains to daylight somewhere in the yard,” said Greg Dennison, permits coordinator for the Gaithersburg Planning and Code Administration. “Over time, that drain could become clogged and could possibly need to be cleaned out.”

Suspect a clogged drain, especially if your window well didn’t used to fill with water as it does now. But figuring out where the drain connects isn’t always simple. Check whether your townhouse association has plans that show this detail. If not, and if there is a slope, investigate whether a downhill area gets wet in rainstorms from a pipe that could be emptying there. Otherwise, trying to find a clogged drain might mean excavating the window well down to the bottom of the foundation, where the drain tile for your building should be.

Brandon Thompson, sales manager for JDS Home Improvement, a Gaithersburg construction company that specializes in egress windows, said excavating a window well and making the fixes that will keep water from collecting could cost $4,500 to $5,500. “We would remove the existing window well,” he said. “We’d bring an excavator in and dig down to the footer.” There is no way to address the problem otherwise, he said. “We have to go down to the source, to see what is wrong with the drainage.”

If you wanted to upgrade your window to one that fully qualifies as an egress, the cost would be $6,500 to $7,000, Thompson estimated. Given how much it would cost to redo your current window, the upcharge may be worth it because it would give you — or future owners — more options for how to use the basement.

David Arias, owner of Drainage & Erosion Solutions in Falls Church, Virginia, said the pictures you sent appear to show that the window well has sunk and that nearby soil slopes toward the house, probably because of soil settling and erosion. He’d inspect to make sure, then send in a crew to dig out the window well and reposition it, which might require adding another section. They’d also regrade so that water flows away from the house. Those steps, plus a tight cover, should fix the problem for around $3,000 to $5,000, he estimated.

Arias said adding a drain pipe isn’t usually possible because most lots don’t have a good place for the water to empty, other than piping it inside the house, which is not ideal. But as a last resort, both he and Thompson said, the company could install a sump pump in the window well. That would save you from having to bail out the water by hand. But it would protect your basement only as long as the power stays on.

You may also want to consider improving drainage issues near your house and then seeing if that’s enough to keep the window well dry. The local code requires at least 6 inches of drop in the first 10 feet out from a foundation, Dennison noted. But he said he’s seen numerous cases where the material that was used to backfill around a foundation gradually settled, causing the surface to slope toward the house, rather that away from it. Filling in the depression with mulch doesn’t change the way the water moves; the fill should be a low-porosity soil, such as clay. Using bins as water diverters still lets water flow through the gaps. Figure out a way to keep water from flowing there, such as by extending gutter downspouts or by building a swale that diverts surface flow.