The 30-day rule for shares, with a worked example
If you sell shares and buy the same shares back within 30 days, the sale isn't matched to your average cost. It's matched to the new purchase first. Here's how that works, with an example you can follow.
Guide for 2025/26 tax year · Updated 23 November 2026
The matching order
When you sell shares, HMRC matches the sale to purchases of the same company's shares in this order (HMRC Capital Gains Manual CG51560):
- Same day: shares bought on the day of the sale.
- Next 30 days: shares bought in the 30 days after the sale.
- Section 104 holding: everything else, treated as one pool at its average cost.
The second rule is the 30-day rule, often called "bed and breakfasting".
A worked example
Sam holds 2,000 shares in a fictional company, Northwind, in a general investment account. The pool cost £8,000 in total, an average of £4 a share. Fees are left out to keep the sums simple.
| Date | Trade | Shares | Amount |
|---|---|---|---|
| 10 June 2025 | Sell at £6 | 1,000 | £6,000 received |
| 24 June 2025 | Buy at £5.50 | 400 | £2,200 paid |
The buy is 14 days after the sale, so 400 of the shares sold are matched to it. The other 600 come from the pool.
- 400 shares matched to the buy-back: proceeds are 400 ÷ 1,000 × £6,000 = £2,400. The cost is the £2,200 paid. Gain: £200.
- 600 shares matched to the pool: proceeds are £3,600. The cost is 600 ÷ 2,000 × £8,000 = £2,400. Gain: £1,200.
- Total gain on the sale: £200 + £1,200 = £1,400.
The 400 shares bought back are used up by the match, so they don't join the pool. Afterwards the pool holds 1,400 shares at a cost of £5,600.
When it doesn't apply
- It only matches purchases by the same person, in the same capacity. If your spouse or civil partner buys the shares back, their purchase isn't matched to your sale.
- It doesn't apply to shares you acquire while you're not UK resident.
For more on spouses and joint holdings, see joint accounts, spouses and foreign shares.
Spotting 30-day matches in your spreadsheet
- Drop your statements onto BrokerCSV with the Dates as 2025-04-06 option ticked (it's on by default), so the dates sort properly in Excel.
- Put every trade in one sheet and sort by holding, then by date. Each company's trades then sit together in order.
- For each sale, look at the rows just below it. Any buy of the same holding dated within 30 days after the sale is matched first.
With dates in column A, holdings in B, Buy or Sell in C and quantities in D, this formula on a sale row adds up the shares bought back in the next 30 days:
=SUMIFS(D:D, B:B, B2, C:C, "Buy", A:A, ">"&A2, A:A, "<="&A2+30)
Then work out each gain as in how to work out capital gains on shares. HMRC's HS284 helpsheet for 2025 has further examples.
Get your statements into a spreadsheet
Convert a statementThis guide explains the general rules and how to get the numbers out of your statements. It isn't tax advice: check GOV.UK or ask an accountant about your own situation.
More guides
- How to work out capital gains on shares for Self Assessment
- How to total your dividends and interest for Self Assessment
- What to send your accountant from your broker statements
- Trading 212 and Self Assessment: what to report and where to find it
- ISA or general investment account: what goes on your tax return
- Joint accounts, spouses and foreign shares: capital gains basics
- Broker statement guides