It' is, as you say, complicated. It's probably worth getting an accountant to check it over, as various things will impact what you pay, for example whether you are a higher rate taxpayer, or whether you have already used your Capital Gains allowance for this year. You also need to base it on market value of the home, even if you discount it because you are selling to a friend.
In essence, you'll get relief for the period you lived there and the past nine months, so if you sold it now, you've owned it for 22 years, but get relief for 9 years + 9 months.
You can also offset expenditure on improvements, and your yearly CGT allowance.
So, for example, if the market value of the property is £200,000 now, there is an increase of £127,500. Take away, say, £10,000k on improvements = £117,500.
9year 9 months/22 years = 44%, so you get relief on that of 44%. So 117,500 * 0.56% = 65,800 left to pay tax on.
Your yearly CGT allowance is 12,300, so that would bring the taxable gain to 63,500. On which you pay 18% if you are a basic rate taxpayer, 28% if you are a higher rate payer.