Oh yes, it's complicated alright - that's how tax advisors make their fees.
You need to search for HMRC Helpsheet HS283 on their website, read and inwardly digest. There are plenty of examples provided on how things work.
The final 36 months of your ownership will not normally count in terms of capital gain in that period. This is good, because property prices have kicked off again in the last couple of years. However the period between when it ceased to be your principal private residence, and 36 months ago will require a CGT assessment. To do that you may well have to employ a valued to advise you as HMRC May not just accept a random figure you might generate for the two valuations. The difference between the two is your net gain, from which you can deduct your personal CGT allowance for around £11k, unless you have any other gains in this tax year.
Having deducted your allowance, you are due to pay tax at 28% on any positive residue, unless you are a higher rate taxpayer, when the rate is higher.