Deductions & credits

Loans have nothing to do with cost basis.  Your starting basis is $500.  Then, you can include the cost of permanent improvements, and you must subtract depreciation you claimed or could have claimed.

 

Let's go way from a rental and look at a simple investment.  You buy for $500 and sell for $1000.  You have a $500 capital gain.  Suppose you paid all cash, and get $1000 of proceeds.  Your gain is $500.  Suppose you paid $100 down and $400 loan, therefore you only get $500 proceeds after selling.  Your gain is still $500.  Suppose you refinanced (borrowed) an additional $500, so your loan was $900.  You still have a capital gains of $500, the difference is just that you took some of the proceeds early as part of the loan.