The order HMRC uses
HMRC's helpsheet HS284 says shares you sell are matched in this order:
- shares bought on the same day as the sale;
- shares bought in the 30 days after the sale (the "bed and breakfasting" rule), if you were UK resident when you bought them;
- shares in your Section 104 holding (the average cost of the rest).
HMRC's example (HS284 Example 2)
Mr Schneider held 9,500 shares for years. He sold 4,000 on 30 Aug 2025 for £6,000, and bought 500 more on 11 Sep 2025 for £850.
- The 11 Sep purchase is within 30 days, so 500 of the shares sold are matched with it.
- The other 3,500 come from his Section 104 holding.
| The 500 shares matched under the 30-day rule | £ |
|---|---|
| Their share of the sale: 500 ÷ 4,000 × £6,000 | £750 |
| Cost: the 500 bought on 11 Sep | £850 |
| Loss on these 500 | £100 |
The 3,500 from the holding use the holding's average cost (HMRC doesn't give his cost, so we stop there; see Section 104 pool example for a full pool example).
Why it matters
- Selling at a loss and buying back within 30 days may cancel the loss you hoped for.
- It only looks at the same company's shares of the same class.
- Buying back inside an ISA isn't caught, because ISA shares are outside CGT (ISAs and pensions).
Working it out with Get My Gains
Get My Gains works out Capital Gains Tax on your shares in your browser, with nothing uploaded, using these same HMRC rules. It reads Trading 212, Freetrade, Interactive Brokers and Hargreaves Lansdown files (other brokers' files can be matched column by column), and leaves out ISA and pension accounts. It's free to check your gains and estimated tax.
Work out your shares tax See an example report
Official guidance
This guide is general information, not tax advice or investment advice. It covers individuals who are UK residents. It is not connected to or endorsed by HMRC. Check HMRC's guidance or ask an accountant before you file.
Checked against HMRC helpsheet HS284 (2026, updated 6 Apr 2026) on 11 Nov 2026.
More guides: shares guides · all guides · Section 104 pool example · CGT on shares, explained