The cleanest answer is: invest if your after-tax mortgage rate is meaningfully below your expected after-tax investment return, and pay off the mortgage if it is not. For most U.S. homeowners with mortgage rates between 3% and 5% (locked in during 2020 to 2022), the math favors investing. For homeowners with rates above 6% to 7% (late 2023 onward), the math is closer, and the answer depends more on personal preference, tax situation, and proximity to retirement.

The mortgage rate side of the equation. Your mortgage's after-tax cost depends on whether you can deduct the interest. Under the 2017 Tax Cuts and Jobs Act, mortgage interest is deductible only if you itemize, and the standard deduction has been raised to $14,600 single / $29,200 married filing jointly for 2024 (and adjusted upward for 2025-2026). The result: most mortgage holders take the standard deduction and get no tax benefit from mortgage interest. For those who itemize, only the marginal interest above the standard deduction effectively reduces tax. Per IRS Publication 936, the deduction is also limited to interest on the first $750,000 of acquisition debt for loans originated after December 15, 2017.

If you take the standard deduction, your after-tax mortgage rate equals your stated mortgage rate. A 6.5% mortgage costs 6.5% per year. If you itemize and your marginal federal rate is 24% with no state tax deduction limits, your after-tax mortgage rate is roughly 4.94% (6.5% × (1 - 0.24)).

The investment return side of the equation. The S&P 500's long-run total return is approximately 9% to 10% nominal and 7% real (after inflation), per Federal Reserve and Robert Shiller historical data. Most financial planners use 7% real or 8% nominal for retirement projections. Your after-tax return depends on the account:

Tax-advantaged accounts (401(k), IRA, HSA). Returns are not taxed annually. Traditional accounts grow tax-deferred and are taxed at withdrawal at ordinary rates. Roth accounts grow tax-free with tax-free withdrawals after age 59 1/2 and 5-year rule satisfied. The expected after-tax return on tax-advantaged accounts is usually similar to or higher than the gross expected return because the tax drag is eliminated.

Taxable brokerage accounts. Long-term capital gains and qualified dividends are taxed at 0%, 15%, or 20% depending on income (IRC § 1(h)). Short-term gains and ordinary dividends are taxed at ordinary rates. For most middle-income investors, 15% is the relevant rate. Expected after-tax return on a taxable account at the 15% LTCG rate is roughly 7% × (1 - 0.15) = 5.95% nominal (lower than the 7% gross rate but still above many mortgage rates).

The math for typical scenarios.

3.0% mortgage, 401(k) with employer match. The match alone is a 50% to 100% return on the contribution. Easy: invest, do not prepay the mortgage. The math is overwhelming.

4.5% mortgage, taxable brokerage. 4.5% mortgage versus ~6% expected after-tax taxable return. Math favors investing, but the margin is narrow. Most planners would invest.

6.5% mortgage, taxable brokerage. 6.5% versus ~6% after-tax taxable return. Roughly even. The mortgage is a guaranteed return; the market return is expected but not guaranteed. Many planners would lean toward mortgage prepayment for the certainty.

7.5% mortgage, taxable brokerage. 7.5% versus ~6% after-tax taxable return. Math favors mortgage prepayment.

The order of operations most planners recommend. Even with high mortgage rates, the typical recommended sequence is: (1) capture employer 401(k) match in full; (2) pay off any debt at 8%+ APR; (3) build emergency fund; (4) max out tax-advantaged accounts (Roth IRA, HSA, 401(k)); (5) only after the above, allocate remaining surplus between mortgage prepayment and additional taxable investing. Mortgage prepayment is rarely the top priority, even at high rates, because tax-advantaged accounts have unique value that is lost forever if not contributed in the year (IRA contributions cannot be made up later, and the tax deferral on 401(k) cannot be retroactively claimed).

The non-financial factors.

Risk tolerance. Mortgage prepayment is a guaranteed return. Stock market returns are an expected return with substantial year-to-year variability. The S&P 500 has had drawdowns of 30% to 50% in 1973-1974, 2000-2002, 2007-2009, and shorter shocks in 2020 and 2022. If a 30% portfolio drawdown would change your behavior (selling at the bottom, panicking about retirement timing), the certainty of mortgage prepayment may be worth the slightly lower expected return.

Liquidity. Money invested in a taxable brokerage account can be sold and accessed within days. Money paid into the mortgage is tied up in home equity and can only be accessed by selling the home or taking a HELOC or cash-out refinance. For households without large emergency funds, prepaying the mortgage can leave them illiquid in a financial shock.

Retirement proximity. A retiree or near-retiree benefits more from mortgage prepayment than a 30-year-old. Eliminating the mortgage payment reduces required retirement income, lowers the sequence-of-returns risk in early retirement years, and provides housing-cost certainty. Many financial planners recommend entering retirement mortgage-free even if the math during accumulation favored investing.

Behavioral. People who would not actually invest the difference (who would let the surplus drift into checking and get spent on other things) get the certainty of mortgage prepayment without the comparison cost. The math assumes you actually invest the difference; if you wouldn't, the math doesn't apply to you.

The hybrid approach. Many homeowners do both: continue investing in tax-advantaged accounts while making modest extra principal payments on the mortgage. A typical pattern is contributing the full 401(k) match plus Roth IRA, then splitting any remaining surplus 70/30 between additional 401(k) and extra mortgage principal. Over 10 to 15 years, this often produces both substantial retirement savings and a paid-off mortgage by the time of retirement.

Refinance first, decide second. If your mortgage rate is above current market rates, refinance before deciding. The decision math changes substantially when your rate moves from 7% to 5%.

Don't forget property tax and insurance. Even with a paid-off mortgage, you still pay property tax, homeowner's insurance, and HOA dues. The "freedom from mortgage payment" feeling at payoff is real but slightly less complete than people imagine. In some high-tax states (New Jersey, Illinois, New York, Texas), property tax alone can run $8,000 to $20,000+ a year on a typical home.

Below 5% mortgage rate, math favors investing. Above 6.5%, the question gets close. Capture the employer 401(k) match before considering mortgage prepayment, no matter what your rate is.