Deductions & credits

your mortgage does not affect the gain just the net proceeds you get.  gain = sales price less sales and closing costs less your tax basis in the property