Cost basis methods for stocks: FIFO, LIFO, and specific identification

TrackMyShares Team

When you sell shares of a stock you have purchased multiple times at different prices, a simple question arises: which shares did you sell? The answer depends on the cost basis method you use, and it can make a significant difference in how much capital gains tax you owe.

In this guide, we compare the three main cost basis methods for individual stocks, walk through worked examples using the same data, and explain how to choose the right method for your situation.

Disclaimer: This article is for informational purposes only and does not constitute financial or tax advice. Consult a qualified tax professional before making investment decisions based on tax considerations.

What is cost basis

Your cost basis is the total amount you paid to acquire an investment, including the purchase price and any transaction fees or commissions. When you sell the investment, your capital gain or loss is the difference between the sale proceeds and your cost basis.

Capital Gain (or Loss) = Sale Proceeds - Cost Basis

If you bought 100 shares of a stock at $40 per share and paid a $5 commission, your cost basis is $4,005. If you later sell those shares for $50 each (receiving $4,995 after a $5 commission), your capital gain is $990.

This is straightforward when you have a single purchase. But most investors buy the same stock multiple times, building their position gradually. When you later sell some (but not all) of your shares, you need a way to determine which shares you sold and what their cost basis was.

That is where cost basis methods come in.

The example we will use throughout this guide

To make comparisons clear, we will use the same scenario for all three methods. Suppose you made the following purchases of XYZ stock over the course of a year:

LotDateSharesPrice per shareTotal cost
Lot 1January 15, 2025100$40$4,000
Lot 2May 10, 2025100$55$5,500
Lot 3September 20, 2025100$45$4,500

You now hold 300 shares with a total cost of $14,000.

On December 15, 2025, you sell 100 shares at $60 per share, receiving $6,000 in proceeds. All three lots have been held for less than one year at the time of the sale (so any gain would be short-term for Lot 2 and Lot 3, and Lot 1 is approaching the one-year mark but has not crossed it yet).

Which 100 shares did you sell? Your cost basis method determines the answer.

FIFO (First In, First Out)

How it works

FIFO assumes you sell your oldest shares first. This is the default method used by most brokers unless you specify otherwise.

Applying FIFO to our example

Under FIFO, the 100 shares you sell on December 15 are the 100 shares from Lot 1, purchased on January 15 at $40 per share.

  • Sale proceeds: $6,000
  • Cost basis (Lot 1): $4,000
  • Capital gain: $2,000

Since Lot 1 was purchased on January 15, 2025 and sold on December 15, 2025, the holding period is 11 months. This is a short-term capital gain of $2,000, taxed at your ordinary income rate.

If you had waited just one more month (until January 16, 2026), the gain would have qualified as long-term, potentially saving you hundreds of dollars in taxes.

When FIFO works well

FIFO is simple and automatic. You do not need to track which lots you are selling because the method is deterministic. It works well when you are not actively optimizing for taxes and prefer simplicity.

When FIFO is less favorable

In a market where a stock has generally trended upward, your oldest shares tend to have the lowest cost basis. This means FIFO often produces the largest gains (or smallest losses), which may not be ideal from a tax perspective.

LIFO (Last In, First Out)

How it works

LIFO assumes you sell your most recently purchased shares first. This method is the opposite of FIFO.

Applying LIFO to our example

Under LIFO, the 100 shares you sell on December 15 are the 100 shares from Lot 3, purchased on September 20 at $45 per share.

  • Sale proceeds: $6,000
  • Cost basis (Lot 3): $4,500
  • Capital gain: $1,500

Since Lot 3 was purchased on September 20, 2025 and sold on December 15, 2025, the holding period is about 3 months. This is a short-term capital gain of $1,500.

Comparing LIFO to FIFO

In this example, LIFO produces a gain of $1,500 versus FIFO's $2,000. That is $500 less in taxable gain. For an investor in the 24% tax bracket, this saves $120 in taxes.

When LIFO works well

LIFO tends to produce smaller gains (or larger losses) when a stock has generally risen over time, because your most recent purchases are at higher prices. This can be beneficial when you want to minimize your current tax bill.

When LIFO is less favorable

If the stock has been declining, your most recent shares may have been purchased at lower prices than your earlier shares. In that case, LIFO could actually produce larger gains than FIFO.

Specific identification

How it works

Specific identification allows you to choose exactly which lot to sell. Instead of following a predetermined order (oldest first or newest first), you select the specific shares that produce the most favorable outcome for your situation.

Applying specific identification to our example

With specific identification, you review all three lots and choose which 100 shares to sell.

LotCost basis per shareGain per share at $60 sale priceTotal gain on 100 shares
Lot 1$40$20$2,000
Lot 2$55$5$500
Lot 3$45$15$1,500

Choosing Lot 2 (purchased at $55) produces the smallest gain of just $500. Compared to FIFO ($2,000) and LIFO ($1,500), specific identification saves you significantly more on taxes.

  • Sale proceeds: $6,000
  • Cost basis (Lot 2): $5,500
  • Capital gain: $500

For an investor in the 24% tax bracket, the tax on this gain is $120, compared to $480 under FIFO and $360 under LIFO.

When specific identification works well

Specific identification is the most flexible method and allows the greatest tax optimization. It is ideal when:

  • You have multiple lots purchased at meaningfully different prices
  • You want to minimize gains in a high-income year
  • You want to maximize losses for tax-loss harvesting
  • You want to control whether gains are short-term or long-term by choosing lots with specific holding periods

When specific identification is less practical

Specific identification requires you to track every lot individually and designate which lot you are selling at the time of the sale. It also requires more record-keeping, which can become burdensome if you make frequent trades.

Comparison table

FactorFIFOLIFOSpecific identification
How it worksSells oldest shares firstSells newest shares firstYou choose which shares to sell
SimplicityVery simple, automaticSimple, automaticRequires manual selection
Tax optimizationLimitedModerateMaximum flexibility
Record keepingMinimalMinimalDetailed lot tracking required
Default at brokersYes (most common)NoAvailable on request
Best forPassive investors who prefer simplicityInvestors in rising markets wanting smaller gainsActive tax planners who want full control

Using our example, here is how the three methods compare side by side:

MethodLot soldCost basisGainTax at 24%
FIFOLot 1 ($40/share)$4,000$2,000$480
LIFOLot 3 ($45/share)$4,500$1,500$360
Specific IDLot 2 ($55/share)$5,500$500$120

The difference between the best and worst outcome in this example is $360 in tax on a single sale of 100 shares. Over a year of active trading, these differences can add up substantially.

Average cost: for mutual funds only

You may have heard of the average cost method, which calculates your cost basis by dividing the total cost of all shares by the total number of shares. This produces a single blended cost per share.

It is important to know that, per IRS rules, the average cost method is only available for mutual fund shares and shares acquired through dividend reinvestment plans. You cannot use the average cost method for individual stocks or ETFs that you purchased on the open market.

If you hold mutual funds, average cost can simplify your record-keeping because you do not need to track individual lots. Your fund company typically calculates this for you automatically.

How to choose the right method

There is no single best method for all situations. The right choice depends on your goals, your tax bracket, and how actively you want to manage your taxes.

Consider your current tax bracket

If you are in a high tax bracket this year, minimizing gains through LIFO or specific identification can save meaningful money. If you are in a low bracket (particularly below the 0% long-term capital gains threshold), you might actually want to use FIFO to realize gains at a 0% rate while you can.

Consider the holding period

Sometimes the most tax-efficient choice is not the lot with the highest cost basis, but the lot that qualifies for long-term treatment. A $2,000 long-term gain taxed at 15% ($300) is cheaper than a $500 short-term gain taxed at 37% ($185), but only at the highest tax bracket. For most investors in middle brackets, the short-term gain on a higher-cost lot is still cheaper in absolute terms.

Run the numbers for your specific situation before deciding.

Consider your long-term plan

If you plan to hold remaining shares for many years, the cost basis method matters less in the long run, because you will eventually realize gains on all lots. The method primarily affects the timing of when you recognize gains, not the total amount over time.

However, timing matters for cash flow and for managing your taxable income from year to year. Deferring gains to a year when you expect lower income can be a sound strategy.

Consider simplicity

If tax optimization is not a priority, FIFO is the easiest method. It requires no additional decisions or tracking, and it is what your broker uses by default.

Broker defaults and how to change your method

Most US brokers default to FIFO for individual stock sales. However, you can typically change the default method in your account settings or select specific lots at the time of sale.

To use specific identification, you generally need to:

  1. Contact your broker (or use their online platform) to designate which specific lots to sell at the time you place the order
  2. Confirm the designation in writing or electronically before the settlement date
  3. Keep records of the designation for your tax files

The IRS requires that the specific lot designation be made at the time of the sale, not retroactively. You cannot sell shares and then later decide which lots were sold.

Some brokers also offer additional methods like highest cost (which automatically sells the lot with the highest cost basis first) or lowest cost (which sells the cheapest lot first). These are variations of specific identification that automate the selection process.

How TrackMyShares handles cost basis

TrackMyShares provides comprehensive cost basis tracking that supports multiple methods and gives you visibility into how each method affects your taxes.

Lot-level tracking

Every purchase you record in TrackMyShares is stored as a separate tax lot with its own purchase date, quantity, price, and fees. You can view your lots at any time to see the cost basis and unrealized gain or loss for each one.

Multiple cost basis methods

TrackMyShares supports FIFO and specific identification. When reviewing your portfolio, you can see how different methods would affect your capital gains.

Tax reports with full detail

The capital gains tax report in TrackMyShares generates a detailed breakdown of every sale, showing the cost basis method used, the lot that was sold, the holding period classification, and the resulting gain or loss. This data aligns with what you need for Form 8949 and Schedule D.

See the impact before you sell

Before selling, you can review your lots in TrackMyShares to understand the tax consequences. See which lots have the largest unrealized gains, which qualify for long-term treatment, and which might be candidates for tax-loss harvesting.


Your cost basis method is one of the most straightforward levers you have for managing your capital gains taxes. Whether you prefer the simplicity of FIFO or the precision of specific identification, keeping accurate records of every lot is essential.

Sign up for TrackMyShares to track your lots, compare cost basis methods, and generate tax reports that make filing simpler.