Boot, debt relief and the replacement's basis
Cash or other property received alongside the real estate is "boot". Gain is recognized up to the smaller of the realized gain or the boot. Debt the other side takes over counts as cash received, though debt the taxpayer takes on in return offsets it. A loss on the real property itself is not recognized in a like-kind exchange.
The replacement property's basis keeps the untaxed gain with it:
New basis = value of property received - gain deferred
Worked example: Fabrizio exchanges a warehouse worth $900,000, basis $300,000 and carrying a $200,000 mortgage that the other party assumes, for an office building worth $700,000 with no debt. Realized gain: $600,000. The debt relief is $200,000 of boot, so $200,000 is recognized. New basis: $700,000 - $400,000 deferred = $300,000.