To avoid any capital gain with a 1031 exchange you must be exchanging like properties that have been held for rental income. The IRS has a very broad description for like properties so usually any property will qualify. The amount you need to reinvest is the difference between the price you aquired the property and the price you sell it. The loan balance is not a factor. You can mark up you basis by adding any improvements.
Answered on Jan 26th, 2013 at 10:16 AM