Deductions & credits

The mortgage owed on the house is not part of the calculation for your profit on the home.  For example if you bought the home for $250,000 and sold it for $300,000 you have a $50,000 profit ($300,000 - $250,000) on the home regardless of the amount owed to the mortgage company.

If you bought the home for $250,000 and the value rose so you took out additional money (let's say the value rose to $400,000 and you added $50,000 to your existing $250,000 mortgage) and then you sold when the value was below the $400,000 (let's say that you again sell for $300,000) your gain on the sale is still the $50,000 from above but you don't get that money since you "received" it when you pulled the money out earlier.