Stock Sale Cost Basis Calculator
Calculate cost basis, proceeds, and capital gain or loss using FIFO, LIFO, or Average Cost assumptions.
Enter Purchase Lots
Sale Details
Important: This is an educational estimator, not tax advice. Confirm method eligibility and reported basis with your broker records and IRS rules.
How do I calculate cost basis for stock sale? A practical expert guide
If you have ever asked, “How do I calculate cost basis for stock sale?”, you are asking one of the most important tax and investing questions in personal finance. Cost basis is the amount the IRS lets you treat as your investment in a security. When you sell, your taxable gain or deductible loss is generally the difference between your net sale proceeds and your adjusted cost basis. Getting it right can mean paying the right amount of tax, avoiding notices, and keeping cleaner records.
In plain terms, cost basis usually starts with what you paid for shares, plus certain transaction costs such as commissions or fees. Then it can be adjusted over time for events like stock splits, return of capital distributions, corporate actions, reinvested dividends, and wash sale adjustments. The final number used at sale is called your adjusted basis.
The core formula
- Gross proceeds = shares sold × sale price per share
- Net proceeds = gross proceeds minus selling commission/fees
- Original basis = shares purchased × purchase price plus buying commission/fees
- Adjusted basis = original basis plus or minus required tax adjustments
- Capital gain or loss = net proceeds minus adjusted basis of shares sold
Step-by-step process to calculate stock sale basis correctly
1) Gather all transaction records
Start with brokerage confirmations, account statements, and your Form 1099-B. For older or transferred shares, your broker may not have complete basis details, so you may need your own records. If shares were acquired over many years, build a lot-by-lot spreadsheet: date, shares, price, fees, and notes on actions like splits or spin-offs.
2) Identify tax lots and accounting method
If you bought the same stock multiple times, you own multiple lots with different costs. Your cost basis depends on which lot(s) are considered sold:
- FIFO: earliest shares sold first. Common default if no lot instruction was given.
- Specific identification: you select exact lots at sale time and keep written confirmation.
- Average cost: common with mutual fund shares; not usually used for individual stock positions unless account rules allow it.
Specific identification can materially change taxes because you can choose higher-basis lots to reduce gains or lower-basis lots when strategic. But the election must be done correctly and documented with your broker.
3) Include commissions and fees
Buy-side fees usually increase basis. Sell-side fees reduce proceeds. Many zero-commission platforms still have regulatory or transaction charges on some trades, so check confirmations carefully. Even small fees can matter at scale.
4) Adjust for corporate actions
Splits do not change your total basis but change basis per share. Spin-offs allocate basis between old and new securities based on fair market values. Return of capital typically reduces basis. Reinvested dividends add to basis because they are generally taxed when paid, then treated as new purchases. Missing these adjustments is one of the most common causes of overstated gains.
5) Calculate holding period
Holding period determines whether gains are short-term or long-term. Generally, more than one year is long-term. For many investors, this distinction has major tax impact because long-term rates are often lower than ordinary income rates.
Federal tax rate context: real threshold data investors should know
The table below summarizes widely cited IRS long-term capital gain brackets (2024 tax year filing framework). These numbers are useful for planning lot selection and timing.
| Filing Status | 0% LTCG Rate Up To | 15% LTCG Rate Range | 20% LTCG Rate Above |
|---|---|---|---|
| Single | $47,025 | $47,026 to $518,900 | $518,900 |
| Married Filing Jointly | $94,050 | $94,051 to $583,750 | $583,750 |
| Head of Household | $63,000 | $63,001 to $551,350 | $551,350 |
In addition to these rates, higher-income taxpayers may owe the 3.8% Net Investment Income Tax (NIIT), which applies once modified adjusted gross income crosses statutory thresholds:
| Filing Status | NIIT Threshold (MAGI) |
|---|---|
| Single / Head of Household | $200,000 |
| Married Filing Jointly | $250,000 |
| Married Filing Separately | $125,000 |
Example: lot-by-lot basis calculation
Suppose you purchased 100 shares at $40 with a $5 fee, then later 60 shares at $52 with a $5 fee. You sell 120 shares at $58 with a $6 sell fee.
- Lot 1 basis per share = (100×40 + 5) / 100 = $40.05
- Lot 2 basis per share = (60×52 + 5) / 60 = $52.08
- Net sale proceeds = (120×58) – 6 = $6,954.00
Under FIFO, you sell all 100 shares from Lot 1 and 20 shares from Lot 2:
- Cost basis sold = (100×40.05) + (20×52.08) = $5,046.60
- Capital gain = $6,954.00 – $5,046.60 = $1,907.40
Under LIFO, you sell 60 shares from Lot 2 and 60 from Lot 1:
- Cost basis sold = (60×52.08) + (60×40.05) = $5,527.80
- Capital gain = $6,954.00 – $5,527.80 = $1,426.20
Same sale price, different lot method, different taxable gain. This is exactly why lot selection matters.
Common mistakes that create tax problems
- Ignoring transfer history: shares moved between brokers can lose lot details if records were incomplete.
- Using wrong default method: assuming specific ID without proper instruction/confirmation.
- Forgetting reinvested dividends: can overstate gains by understating basis.
- Missing split or spin-off basis allocations: often affects long-held positions.
- Overlooking wash sale adjustments: disallowed losses are added to replacement share basis.
- Not reconciling Form 1099-B and Form 8949: mismatch can trigger IRS notices.
How holding period and tax rate planning fit your basis strategy
Cost basis is not only about recordkeeping. It is a planning lever. If you are near the one-year mark, waiting can convert a short-term gain into a long-term gain. If your income is temporarily lower, realizing gains in a lower LTCG bracket can reduce lifetime tax drag. If your portfolio has losses, tax-loss harvesting may offset gains, but wash sale rules must be respected.
Smart investors track three numbers together: embedded gain/loss by lot, holding period by lot, and expected tax bracket. This creates better decisions than looking at performance alone.
Authoritative sources you should use
For official rules and up-to-date thresholds, rely on primary sources:
- IRS Topic No. 703, Basis of Assets (.gov)
- IRS Publication 550, Investment Income and Expenses (.gov)
- U.S. SEC Investor.gov Cost Basis Guidance (.gov)
Record retention and audit readiness checklist
- Keep confirmations for every buy, sell, split, merger, and spin-off.
- Retain dividend records showing reinvested amounts and dates.
- Store broker statements and year-end tax forms in one archive.
- Document any specific ID lot instructions and broker acknowledgments.
- Preserve records for inherited or gifted shares, including valuation date support.
How this calculator helps
The calculator above gives you a fast estimate using common methods. Enter up to three purchase lots, your sale details, and select a basis method. It computes net proceeds, basis allocated to sold shares, gain/loss amount, and a visual comparison chart. Use it for planning and scenario testing before you place a trade or before year-end tax management decisions.
For final filing, compare your calculations to broker-reported 1099-B data and complete Form 8949/Schedule D as required. If you have complex events like wash sales across accounts, ESPP adjustments, RSU sell-to-cover scenarios, or inherited positions with stepped-up basis considerations, a licensed tax professional is worth the cost.
Final takeaway
To calculate cost basis for a stock sale, think in this order: identify the exact shares sold, compute adjusted basis accurately, subtract from net proceeds, then classify holding period for tax rate treatment. Precision at each step protects you from overpaying tax and from reporting errors. The more lots and history you have, the more valuable a repeatable process becomes.