capital gain = selling price - purchase price or cost basis, 跟還貸款無關
selling price 300K, cost basis 200K, loan paid off, capital gain = 300 - 200 = 100K, you get 300K back (ignore costs, before tax)
selling price 300K, cost basis 200K, loan 100K, principal 100K, capital gain = 300 - 200 = 100K, you get 200K back (ignore costs before tax)
selling price 180K, cost basis 200K, loan paid off, capital gain = -20K, you get back 180K