There may be a straightforward solution for another kind of “lock-in effect” paralyzing the nation’s housing market: fix the tax code.

Recent analysis from Moody’s Analytics, led by Chief Economist Mark Zandi and Deputy Chief Economist Cristian deRitis, points directly to outdated capital gains tax caps as the culprit that is keeping millions of homes off the market and out of reach for families who need them most.

According to the report, the problem starts with too many empty-nest seniors “locked in” to homes that no longer fit their needs. But instead of selling and downsizing to a smaller home, the prospect of steep capital gains taxes keeps them in their bigger homes.

The problem is especially acute in high-cost metro areas, where decades of property appreciation means selling even a modest home can trigger a six-figure tax bill. This “misallocation” in the housing market results in a “logjam” where nearly 6 million older Americans reside in houses far larger than necessary, while growing families are crammed into spaces that are too small and millions of young households stay stuck in rental limbo.

This lock-in effect, which is separate from the one caused by high mortgage rates, stems from the Taxpayer Relief Act of 1997, which introduced a capital gains exclusion of $250,000 for single filers and $500,000 for married couples. But these thresholds haven’t budged in almost 30 years. If indexed to home price growth, today’s exclusions would be $885,000 for individuals and $1.77 million for couples. Instead, the thresholds remain static, and more homeowners face massive taxes for moving, especially in states like California and Florida.