Many companies featured on Money advertise with us. Opinions are our own, but compensation and
in-depth research may determine where and how companies appear. Learn more about how we make money.

senior couple in living room
AMV Photo—Getty Images

If you're in or near retirement and still have a mortgage, you have plenty of company. People in their fifties and sixties are far more likely to have mortgages than prior generations had at their age. And the balance on today's mortgages is higher than ever (see chart).

You may have purchased or refinanced later in life and not had enough time to repay. Or you may believe you'll get higher returns by investing in the stock market rather than paying off a low-rate loan.

In fact, you usually benefit from owning your home outright before retiring—and not just for the peace of mind—says Allan Roth, a certified financial planner at Wealth Logic in Colorado Springs. Having no monthly payment means you'll pull less money out of your portfolio, potentially lowering your tax bill. Your nest egg may last longer, especially if you retire into a bad market, since draining too much from a shrinking pool is a sure way to run out of money fast.

Still, as you enter retirement, there are cases in which, even if you have the cash, not retiring your mortgage is a better choice. Here are three of them.

Money

Other loans are costlier. Most other debt, such as PLUS education loans (currently 6.84%), are more expensive than mortgage debt (30-year fixed rates have been as low as 3.4% in recent years). So repay those other loans first. That's particularly true for PLUS loans if your income is too high to qualify for a student loan interest deduction ($160,000 for couples and half that for singles).

Your savings would suffer. Unless you have already saved plenty, you should make full use of retirement account tax breaks. The 401(k) contribution limit in 2016 for people 50 and older will be $24,000, including $6,000 in catch-up contributions. And while people often consider cashing in retirement savings to pay off a mortgage, incurring a fat tax bill to pay off a low-rate loan makes little sense.

You would be cash poor. Having too much of your net worth tied up in your home leaves you vulnerable to large unexpected expenses such as nursing-home bills, says Thomas Anderson, author of The Value of Debt in Retirement.

What are the danger signs? A mortgage-free home isn't a good idea if you don't have enough money left over to live comfortably and pay your bills, says Michael Kitces, a partner at Pinnacle Advisory Group in Columbia, Md. Roth, for his part, thinks his clients' home equity before and during retirement shouldn't exceed half of their net worth. You might believe tapping that equity would be easy in an emergency, but it could be tough. Lenders may balk at giving you a mortgage because your retirement income is too low, and can freeze or shut down home-equity lines of credit as they did during the recession.

One final note: If you want to keep a mortgage balance solely to invest in stocks, think twice. Repaying your loan guarantees a return equal to its interest rate. But given stocks' unpredictability, Kitces calculates you'd have to expect average annual returns of at least 10% to fully compensate for the chance they'd be much worse. Such a bet could be risky if you seek a peaceful retirement.

Read next: Should I Try to Pay Off My Mortgage More Quickly?