Cost Basis Calculator

Free cost basis calculator — compute gain or loss per lot using FIFO, LIFO, or average cost methods for stocks, ETFs, and mutual funds.

About the Cost Basis Calculator

When you sell shares purchased at different times and prices, the cost basis method you choose directly affects your taxable gain or loss. FIFO (first in, first out) sells the oldest shares first, LIFO (last in, first out) sells the newest, and average cost divides total cost equally among all shares. Each method can produce a different tax outcome.

Our Cost Basis Calculator lets you enter multiple purchase lots and a sale quantity, then compares the gain or loss under FIFO, LIFO, and average cost. Use it to choose the most tax-efficient method before placing a sell order. Tax-lot selection affects not just your current tax bill but also your overall portfolio strategy. Choosing FIFO might simplify record-keeping, but specific identification could save you thousands by allowing you to sell the highest-cost shares first. The difference between methods can be especially dramatic after years of dollar-cost averaging into the same stock.

Why Use This Cost Basis Calculator?

Choosing the right cost basis method can save hundreds or thousands in taxes on a single sale. Selling high-basis lots first reduces the taxable gain, while selling low-basis lots defers the tax savings to the future. This calculator makes the comparison instant so you can make an informed decision with your broker before executing the trade.

How to Use This Calculator

  1. Enter each purchase lot: date (for reference), number of shares, and price per share.
  2. Enter the number of shares you plan to sell.
  3. Enter the sale price per share.
  4. Review the gain or loss under FIFO, LIFO, and average cost methods.
  5. Choose the method that best fits your tax situation.
  6. Inform your broker of your lot selection method before or at the time of sale.

Formula

FIFO: sell oldest lots first. LIFO: sell newest lots first. Average Cost: basis per share = total cost of all shares / total shares owned. Gain = (Sale Price - Cost Basis) x Shares Sold.

Example Calculation

Result: FIFO gain: $2,250 / LIFO gain: $1,200 / Avg gain: $1,890

You own 100 shares in three lots. Selling 60 shares at $80: FIFO sells the 50 shares at $40 and 10 at $55 for a $2,250 gain. LIFO sells 20 at $70 and 30 at $55 and 10 at $40 for a $1,200 gain. Average cost basis is $52.50/share, so the gain on 60 shares is $1,650. LIFO produces the smallest taxable gain in this scenario.

Tips & Best Practices

Why Cost Basis Methods Matter

The IRS allows investors to choose how they identify shares sold. The choice directly impacts the capital gain or loss reported. In a portfolio with lots purchased at different prices, the difference between FIFO and specific identification can be thousands of dollars in tax savings on a single transaction.

FIFO vs LIFO vs Average Cost

FIFO sells the oldest shares first. In steadily rising markets, these are the cheapest shares, producing the largest gain. LIFO sells the newest shares, which in rising markets have higher cost bases and lower gains. Average cost divides the entire portfolio cost by total shares, landing somewhere in between. Each approach has administrative and tax trade-offs.

Practical Recommendations

For individual stocks and ETFs, use specific identification with your broker to hand-pick which lots to sell. This gives maximum control. For mutual funds in taxable accounts, average cost is the simplest and is widely supported by fund companies. In tax-advantaged accounts (IRA, 401k), cost basis method is irrelevant because gains are not taxed until withdrawal.

Frequently Asked Questions

What is cost basis?

Cost basis is the original purchase price of an investment plus any commissions or fees. It is subtracted from the sale price to determine the capital gain or loss for tax purposes. Accurate cost basis tracking is essential for correctly reporting investment income to the IRS.

Which cost basis method is best?

It depends on your tax situation. In a rising market, LIFO or specific identification of high-cost lots minimizes the current taxable gain. In a declining market, FIFO may produce a larger deductible loss. Average cost simplifies record-keeping but offers less tax-planning flexibility. Consult a tax advisor for your specific situation.

What is the wash sale rule?

If you sell shares at a loss and repurchase substantially identical shares within 30 days before or after the sale, the IRS disallows the loss. The disallowed loss is added to the cost basis of the replacement shares. This rule prevents investors from artificially generating tax losses while maintaining their positions.

Can I change my cost basis method after selling?

For stocks and ETFs, you can choose different methods for each sale (specific identification vs FIFO). For mutual funds, once you elect average cost and sell shares under that method, you generally cannot switch back for previously sold lots. New lots going forward can use a different method.

How are dividends reinvested through a DRIP handled?

Each dividend reinvestment creates a new lot with its own cost basis equal to the price paid for those shares. Over time you accumulate many small lots. Average cost simplifies the tracking, but specific identification may offer better tax outcomes for partial sales.

What happens to cost basis in a stock split?

In a stock split, the total cost basis remains the same but is spread over more shares. For example, in a 2-for-1 split, each share basis is halved while the share count doubles. The Stock Split Calculator can help visualize this adjustment.

Related Pages