Millions of homeowners would like to sell their houses but can’t, because buyers are scarce or prices too low. While waiting for the market to improve, a refinancing might be appealing, offering a chance to cut monthly payments.

At first glance, the refinancing decision seems straightforward: If you’ll have the new mortgage long enough for the savings from lower monthly payments to offset the fees associated with modifying your home loan, refinancing looks like it will pay. Today’s extraordinarily low mortgage rates can produce significant payment reductions for anyone who got their mortgage a few years ago when rates were higher.

But another factor can change the balance entirely: How much will you still owe on the new loan after you sell the house? While a new loan with a lower rate may pay in the long run, in some cases the balance a year or two after a refinancing deal can actually be higher on the new loan, wiping out the savings from the lower monthly payment.

The key factor is how long you had the old mortgage. In the standard 30-year fixed-rate loan, the interest charges get slightly smaller every month as you pay down the loan balance, or principal. Since the monthly payment stays the same though, a growing portion goes to principal every month, so that the loan balance falls at a faster and faster rate.

When you refinance, you start the process all over again, with only a very small portion of your payment going to the loan principal. A year or two after refinancing with a new 30-year loan, you’d have made only a tiny dent in the balance. If you’d stuck with the older mortgage, you might have lopped thousands off the balance, leaving more money in your pocket after you sold.

On his website, Jack M. Guttentag, emeritus finance professor at the Wharton School, shows how a refi could backfire on a homeowner in today’s market. In his example, the homeowner has 23 years left on a $300,000 mortgage at 4.125%, and expects to sell in two years.

To reduce the monthly payments, the homeowner refinances to an interest-only adjustable-rate mortgage at the same interest rate. Since the new loan charges nothing for principal, the payment drops from $1,685 to $1,031.

That reduces payments by $15,986 over two years. After accounting for $6,000 in refinancing costs, the total savings are $9,986.

“What he has overlooked,” says Guttentag, “is that if he had stayed with this existing mortgage, he would have paid down the balance by $16,307, which would have resulted in net proceeds at sale $16,307 larger. His supposed gain of $9,986 is actually a loss of $6,321.”

In this example, the homeowner feels safe refinancing to an adjustable-rate loan because with only two years before the expected sale there’s not enough time for rate resets to push the monthly payment through the roof. A more cautious homeowner might refinance to a fixed-rate loan, ensuring the payment would not rise even if the sale plan were scrapped and the new loan was kept for the long term.

If the new adjustable-rate loan produced a dramatic rate cut, the chances of breaking even in only a few years would be better. The odds would also improve if the new loan had a term similar to that remaining on the old loan. A homeowner with 20 years left on a 30-year loan, for example, would probably do better refinancing with a 20-year loan rather than one starting all over again at 30 years, which would require 10 more years of interest payments.

The key factor here is all the costs related to a refinancing deal rather than just the monthly payment. That’s especially important if you expect to sell in the next few years, because there’s little time for savings to offset refinancing costs.

Use the BankingMyWay Refinance Breakeven Calculator, and be sure to click the “View Report” button to see what your loan balance would be after every month’s payment.