I purchased a rental property in 2002 for $107000. I sold in 2018 for $98000. I depreciated it over the years for $85000 and I still owe $60000 what is my cost basis. I also paid closing cost of $14000.
Your sales proceeds are $98000 minus $14000 or $84000
Your taxable gain is $84000 minus $22000 or $62000
How much you owed when you sold the property ($60000) is not germane to your taxable gain
Also, your gain will be subject to either Section 1245 and/or 1250 property. If the rental property included things like stove, refrigerator, etc., or other types of equipment, those should be allocated a selling price less basis, and and gain/loss will be either 1245 gain, or ordinary loss.
Sale proceeds allocated to real property may be subject to Section 1250 gain.