Capital Gains Tax
When you sell a house, Capital Gains Tax (CGT) is calculated on the difference between the sale proceeds and the purchase price plus any capital improvements, inclusive of any legal fees.
Principle Residence Relief
If the house was your home for the whole period of ownership, you should be able to claim Principle Private Residence (PPR) relief which will mitigate the gain, and remove any liability to CGT.
Annual Exemption
However, if it was not your home for the whole period of ownership, you will need to assess how much of the gain is taxable, before applying your annual exemption.
Mortgage Charge
Whether the property has a mortgage charge or not is irrelevant, unless the purchaser takes on the mortgage from the seller, which is rare and actually just forms part of the agreed price (loan instead of cash).
Settling your Mortgage
Having a mortgage to settle when you sell a property may affect your decisions and most certainly your cash flow management, but it has no impact on the CGT liability, which by the way, usually has to be declared and paid within 60 days.