Finance and Budgeting

Cost Basis Lot Matcher

List your purchases and sales to compare four ways of choosing which units were sold.

Your numbers

Purchases
Purchase 1

Purchase 2

Purchase 3

Sales
Sale 1

Result

Gain, first in, first out

$2,200.00

Across the four methods the gain runs from $1,550.00 (highest cost first) to $2,200.00 (first in, first out).

Gain, first in, first out
$2,200.00
Gain, last in, first out
$1,600.00
Gain, highest cost first
$1,550.00
Gain, average cost
$1,930.43
Units sold
120
Units still held
110

Four methods compared

MethodProceedsCost basisGain
First in, first out$4,800.00$2,600.00$2,200.00
Last in, first out$4,800.00$3,200.00$1,600.00
Highest cost first$4,800.00$3,250.00$1,550.00
Average cost$4,800.00$2,869.57$1,930.43

Matches under first in, first out

Sale dateLot boughtQuantityCostProceedsGainHeld
June 20, 2024February 10, 2023100$2,000.00$4,000.00$2,000.00496 days
June 20, 2024August 15, 202320$600.00$800.00$200.00310 days
How this was calculated
  1. Each sale is matched to purchases made on or before the sale date. First in, first out uses the oldest purchase first, last in, first out the newest, and highest cost first the most expensive.
  2. Average cost keeps one pool: the total cost of all units bought so far that are still held, divided by their number. Every sale takes units out of the pool at that average.
  3. Gain for each piece = quantity x (sale price - purchase price). Fees, splits and wash-sale style rules are not included.
  • Which methods you may use, how holding periods count and what rates apply depend on your country and your account, and a broker may choose a default for you. This is an arithmetic comparison, not tax or legal advice.

Calculated using SumPanda.com · https://sumpanda.com/cost-basis-lot-matcher/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the cost basis lot matcher

  1. List each purchase with its date, quantity and price per unit. Add as many lots as you need.
  2. List each sale with its date, quantity and price per unit. Sales are matched against purchases made on or before the sale date.
  3. Choose which method's matches to show in detail: first in first out, last in first out, highest cost first, or average cost.
  4. Read the four-way comparison of cost basis and gain, then the detail table showing which lot each part of a sale came from and how long it was held.

Formula

Gain on a matched piece = quantity x (sale price - purchase price)

First in, first out: oldest lots first

Last in, first out: newest lots first

Highest cost first: the most expensive lots first

Average cost: total cost of units still held / number of units

For average cost, every lot bought up to the sale date joins one pool, and a sale takes units from the pool at that pool's average. Later purchases join the pool at their own cost.

Three purchases and one sale

Buy 100 units at $20 on 2023-02-10, 50 at $30 on 2023-08-15 and 80 at $25 on 2024-03-01. On 2024-06-20 sell 120 units at $40, for proceeds of $4,800.

First in, first out sells the 100 at $20 and 20 of the $30 lot: cost $2,600, gain $2,200. Last in, first out takes the 80 at $25 and 40 of the $30 lot: cost $3,200, gain $1,600. Highest cost first takes the 50 at $30 and 70 of the $25 lot: cost $3,250, gain $1,550. Average cost is $5,500 / 230 = $23.9130 a unit, so the cost is $2,869.57 and the gain is $1,930.43. The gains differ by $650 from the same sale.

Why the method changes the gain

When you buy the same thing at different prices, a sale of part of it has to be matched to specific purchases. The matching changes the cost used and so the gain. Prices that rose over time give a larger gain under first in first out, since the oldest lots are cheapest, and a smaller gain under last in first out or highest cost first.

The total profit over the whole life of the holding is the same, since you spent the same money and received the same proceeds. The methods only move gains between sales and tax years. For a single sale with tax rates you enter yourself, see the Capital Gains Calculator, and for repeated buys the Stock Average Calculator.

What this page does not decide

Which methods you can use, whether you must name lots when you sell, how holding periods are counted and what rates apply depend on your country, your account and your broker. A broker may apply a default method to your sales. Nothing here is tax or legal advice, and no rate is built into the tool.

The same matching ideas are used for goods in a warehouse, shown in the FIFO and LIFO Inventory Valuation Calculator. Use the detail table's days held as a plain count of days, and read your own rules for what counts as a long or short holding.

Assumptions and limits

  • Each sale can only use units bought on or before the sale date, and a sale larger than the units available is rejected.
  • Fees, commissions, stock splits, wash sale style rules and currency changes are not modeled.
  • Quantities can be fractions. Prices are per unit in one currency.
  • Dates are read as calendar dates with no time of day, so same-day purchases and sales are allowed.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

What is a cost basis lot?

A lot is a group of units bought at one time and price. When you sell, the cost of the units you sold depends on which lots they came from, which is why matching rules exist.

What does highest cost first do?

It sells the units you paid the most for first, which usually lowers the gain on that sale. It is an option some brokers offer, but whether you may use it depends on your account and your rules.

Why does average cost have no lot dates?

Average cost merges everything you hold into one pool. A sale takes units from the pool at the pool's average price, so there is no individual lot to point to or hold date to count.

Does the tool tell me what tax I owe?

No. It reports gain per method and the days held, and leaves out rates, brackets and special rules on purpose. Use your own country's rules or an adviser for the tax side.