BrokerCSV

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):

  1. Same day: shares bought on the day of the sale.
  2. Next 30 days: shares bought in the 30 days after the sale.
  3. 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.

DateTradeSharesAmount
10 June 2025Sell at £61,000£6,000 received
24 June 2025Buy at £5.50400£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.

  1. 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.
  2. 600 shares matched to the pool: proceeds are £3,600. The cost is 600 ÷ 2,000 × £8,000 = £2,400. Gain: £1,200.
  3. 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

For more on spouses and joint holdings, see joint accounts, spouses and foreign shares.

Spotting 30-day matches in your spreadsheet

  1. 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.
  2. Put every trade in one sheet and sort by holding, then by date. Each company's trades then sit together in order.
  3. 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 statement

This 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