You will need to calculate periods of residence on a monthly basis.
If the property was your Principal Private Residence (PPR) at some time, then the last 36 months will be deemed to be a period of residence.
You will then need to apportion the period of residence/ownership. I assume that the garden is smaller than half a hectare and that there is no business use (letting is not generally considered business use).
There may be also be deemed residence, but that will depend on your circumstances.
Note that Husband and wife can only have one PPR between them.
You may also deduct improvements you made to the property from your chargeable gains, but not the amount you owe on the mortgage. So to give you an example:
Sale Proceeds 300,000
Acquisition cost (70,000)
230,000
PPR Exemption (155,056)
74,944
Letting relief (40,000)
34,944
Annual Exemption (11,100)
Taxable 23,844
Capital Gains Tax Rate: starts at 18% and is 28% for higher rate (so a maximum of £6,676.72 based on the above example).
PPR Exemption:
(note this is not exact: you will need to use a monthly basis based on exact dates. Your dates are assumed to be on 1 January)
Actual residence:
1.1.2001 - 31.12.2002: 24 months
1.1.2008 - 31.12.2012: 60 months
Plus Last 36 months
Total: 120 months
Length of ownership: 1.1.2001 - 31.10.2015 (assumed sale date): 178 months
120/178 x £230,000 = £155,056