This looks long, but you can relax. And her is why.
The CGT is calculated on a linear basis - you don't revalue it each time you occupy or let. And there is no indexation. Indexation was abolished in 2008, and only companies can now claim it. You take the difference between the net sale proceeds (net of selling costs) and the original cost inclusive of SDLT. You then time apportion the overall gain. The exempt period is (generally) the whole of the period of your occupation plus the last 18 months divided by the whole of the period of ownership.
For example (ignoring transaction costs) - Bought £100,000, sold for £200,000 = £100,000 gain
You moved out after 6 years and then let for 1 year then sold after 10 years of ownership, then the exempt period is 6 plus 18 months - in other words 7.5 divided by 10 = £75,000 exemption.
The chargeable period is then reduced by Lettings Relief which is subject to a cap of the lower of;
a) £40,000
b) the period the property was actually let (1 year out of 10, or 10%)
c) the period the property was actually occupied by you (7.5 years out of 10, or 75% again)
In other words, the Letting Relief cannot be worth anymore than the gain attributable to letting, nor exceed the gain attributable to occupying, nor in any case £40,000. Then there is the annual exemption which is c.£11,000 which may cover whatever is chargeable. You can also get relief for periods where your employer requires you to work in another part of the country or overseas, providing (generally) you re-occupy afterwards.
Sound confusing?....well that is the UK tax code! But in many cases of occupation, moving out, followed by letting and then a sale within 18 months of the final tenant leaving there should be no tax. Bear in mind that all these reliefs have to be claimed - so you still have to notify HMRC when you sell and ask them to issue a tax return for the following April.