Deductions & credits

But what is the gain?  It's not what you owed or the net proceeds but the purchase price 5 years ago.  Mortgage doesn't matter.   Your gain or loss is just the sales price minus cost.  And buying another house doesn't matter anymore.