Deductions & credits

Technically you sold the old car for $16K to the dealer so that is your sales price.  The extra money is part of the "boot" you had to pay so the new vehicle's basis is the 16 + 2 = 18K   Paying off the loan is immaterial to this calculation.