Free Tool

Tax-Lot Cost Basis
Calculator

Bought the same stock in multiple tranches? Calculate your weighted average, FIFO, or LIFO cost basis — and see your unrealised gain — in seconds. Includes a worked UK bed-and-breakfasting example.

Apple Inc. (AAPL) — Buy Lots
Purchase dateSharesPrice (£)Lot cost (£)
7,125.00
4,956.00
3,560.00
7,430.00
Total / Avg140£164.79£23,071.00
Unrealised P&L on full position:+£4,229.00 gain
Cost basis method:

Sale transaction

Result — Weighted Average

Sale proceeds

£11,700.00

Cost basis

£9,887.57

Gain / Loss

+£1,812.43

Avg cost / share

£164.79

Remaining position after sale: 80 shares at avg cost £164.79

For illustration only. This tool does not constitute financial or tax advice. Consult a qualified tax adviser for your specific situation.

What is cost basis?

Your cost basis is the original value of an asset for tax purposes — typically what you paid for it, including any transaction costs. When you sell, your capital gain or loss is calculated as sale proceeds minus cost basis. If you bought the same stock in multiple lots at different prices, you need a rule to decide which shares you're selling. That rule is your cost basis method.

FIFO, LIFO, and Weighted Average

First In, First Out (FIFO)

The oldest shares are deemed sold first. Common default in many jurisdictions. Typically results in larger gains if the stock has risen over time.

Last In, First Out (LIFO)

Most recently purchased shares are sold first. Can reduce gains in rising markets but is not permitted in all jurisdictions (not available in the UK for individuals).

Weighted Average Cost

Total cost divided by total shares — a single blended cost per share. Used in the UK's Section 104 pool, which averages all historic purchases into a single running pool.

UK Bed-and-Breakfasting Rule (30-day rule)

HMRC prevents investors from bed-and-breakfasting — selling shares to crystallise a loss and immediately re-buying them — using a strict share-matching order:

  1. Same-day rule: If you buy and sell the same shares on the same day, the acquisition is matched first.
  2. 30-day rule: Any shares bought in the 30 days following a sale are matched against that sale (at the price you paid on re-purchase), not the Section 104 pool.
  3. Section 104 pool: Everything else is matched against the averaged pool.

The calculator below shows a worked example where a sale followed by a re-buy within 30 days is matched under the 30-day rule — see how the gain calculation changes compared to the pool method.

Portledger does all of this automatically

Portledger's ledger engine applies HMRC Section 104, same-day, and 30-day matching rules automatically across every holding. No spreadsheet. No manual matching. Full audit trail for every cost basis figure.

See how Portledger works
Free Cost Basis Calculator — FIFO, LIFO, Average Cost & Bed-and-Breakfasting | HWSW