All guides

Investing

Cost Basis and Capital Gains: The Tax Math That Decides How Much You Actually Keep

11 min readTonle Editorial

You sold 100 shares of Apple for $18,000 this year. You thought you made $8,000. The IRS disagrees. The difference comes down to cost basis and the tax rate you owe on capital gains. Get this wrong, and you might owe thousands more than expected. Get it right, and you can structure your trades to save real money.

What Cost Basis Actually Is

Cost basis sounds simple: the price you paid. It's not.

Cost basis is the total dollar amount you invested in an asset, measured at the moment you acquired it. It includes the purchase price, but also commissions, fees, and reinvested dividends.

Let's say you bought 100 shares of Vanguard Total Stock Market Fund (VTI) at $225 per share in 2020. That's $22,500. Your broker charged a $10 commission. Your cost basis is $22,510.

Two years later, you bought another 50 shares at $280 each. That's $14,000, plus a $10 commission. Your second position has a cost basis of $14,010.

Now, if you sell all 150 shares at $290 each, you have a sale price of $43,500. But your cost basis across both positions is $36,520. Your capital gain is $6,980. That's the number that gets taxed, not the $43,500.

This matters because cost basis determines your actual taxable gain. Miss it, and you'll either underpay taxes (and face penalties) or overpay because you forgot to include reinvested dividends or assume the wrong purchase price.

The Massive Difference Between Short-Term and Long-Term Capital Gains

How long you hold an investment changes everything about the tax bill.

If you hold an investment for one year or less, it's a short-term capital gain. If you hold it for more than one year, it's a long-term capital gain. The US tax code treats these completely differently.

Short-term capital gains are taxed as ordinary income. If you're in the 24% federal income tax bracket, a $10,000 short-term gain adds $2,400 to your tax bill. Plus state income tax. Plus Medicare surtax if you're high-income. You could easily owe 30-35% of your gain.

Long-term capital gains get preferential tax rates: 0%, 15%, or 20%, depending on your income level. A high-income investor might owe 20% federal plus state tax (maybe 25% total), but they're still paying roughly 35-40% less than if it were short-term.

Here's a concrete example:

You bought 100 shares of Nvidia at $450 in January 2025. In May 2025 (five months later), it's trading at $550. You sell for a $10,000 gain. If you're in the 32% tax bracket, you owe roughly $3,200 in federal tax alone, plus state.

You sell the same stock in February 2026 (one year and one month later). Same $10,000 gain. Now you owe 15% federal long-term capital gains tax (assuming moderate income), which is $1,500, plus a smaller state bill. You save over $1,000 just by waiting one more month.

This is why smart investors track holding periods obsessively. The one-year threshold is the dividing line between an expensive tax bill and a tolerable one.

FIFO, Specific Identification, and Which Method to Use

When you own multiple positions in the same stock and you sell some shares, which shares do you actually sell? The IRS doesn't care which physical shares move; what matters is which cost basis you use.

The default method is FIFO (first in, first out). You sold the shares you bought earliest. If your earliest shares have the highest cost basis, this minimizes your gain. If they have the lowest cost basis, it maximizes your tax bill. Most investors default to FIFO without thinking about it, which is often a mistake.

Specific identification lets you choose exactly which shares you sell. You bought 100 shares at $100, then 100 shares at $150. You decide to sell the 100 shares you bought at $150. You specifically identify them in writing (your broker requires this), and your cost basis is the higher amount. This is powerful for tax optimization.

Average cost is used mainly with mutual funds. You owned 200 shares of a fund with an average cost of $50. You sell 100 shares. Your cost basis for all of them is $50 per share, not the specific prices you paid at different times. Average cost simplifies the math but sacrifices flexibility.

For taxable investment accounts (not retirement accounts), specific identification is almost always better than FIFO. It lets you choose to sell the highest-cost shares first, minimizing your capital gain in years when you need to be tax-efficient, or sell lower-cost shares when you have losses to offset.

Use specific identification when:

  • You own multiple positions in the same security at different prices
  • You're trimming a position rather than closing it entirely
  • You want to harvest losses in one position while staying invested
  • You're managing a concentrated position built up over time

Your broker's interface usually makes this easy: you select the shares you want to sell and confirm the cost basis. Document it clearly so you have records three years later if the IRS asks.

The Wash Sale Rule: The Trap That Costs Real Money

You have a position in Intel that lost $5,000. You sell it, plan to buy it back later at a better price, and use the $5,000 loss to offset gains elsewhere. Smart move, right?

Not if you buy Intel again within 30 days. The wash sale rule says: if you sell a security at a loss and buy a substantially identical security within 30 days before or after the sale, the loss is disallowed. Instead, it's added to the cost basis of the new purchase. You don't lose the tax benefit forever, but you lose it this year.

Substantially identical is broader than you'd think. Buying a different Intel ticker (INTC vs different share class) usually doesn't get you around this. Buying Intel-tracking ETFs might count, depending on the specifics. But buying a different semiconductor company (QCOM instead of INTC)? That's clearly not substantially identical.

The 30-day window is before and after the sale. Sell Intel on December 15th? You can't buy it back until January 14th or later. Buy it back December 10th and you've triggered a wash sale on a sale that hasn't happened yet.

This is important because investors often sell losers at year-end to capture losses, then immediately rebuy when they think the stock has bottomed. If you do this less than 30 days after the sale, you've wasted the tax loss. If you're doing this systematically, you could be leaving thousands on the table every year.

The easiest solution: sell the losing position, and if you want to stay exposed to the sector, buy a different stock or fund for 30+ days. Or sell the position and don't rebuy until 31 days have passed. Your broker can flag wash sales before they happen if you let it.

Long-Term Capital Gains Brackets and Real Tax Rates

The long-term capital gains tax brackets don't align with ordinary income brackets, which confuses everyone. Here's how it actually works:

For 2026, the 15% long-term capital gains rate applies to single filers with taxable income up to $47,025. The 20% rate kicks in above $518,900. Everyone in between pays 0%, 15%, or 20% depending on their exact income.

This means a couple can earn a lot of long-term capital gains and still pay 15%, or even 0% if their total income is low enough.

Quick example: A retired couple with $30,000 in Social Security, $20,000 in ordinary investment income, and $80,000 in long-term capital gains has taxable income of $130,000. They're paying 0% on some of that capital gains and 15% on the rest, not 20%.

The step-up in basis at death is the hidden gem of long-term capital gains. When you inherit an investment, your cost basis is stepped up to the market price on the date of death (or six months later if the estate elects). You inherit a stock worth $100,000 that your parent bought for $20,000 in 1980, your cost basis is $100,000. You sell it the next week and pay zero capital gains tax. This is one of the few ways the tax code genuinely rewards building wealth.

Tax-Loss Harvesting: The Strategy That Actually Works

Tax-loss harvesting is selling a losing position specifically to capture the loss for tax purposes. It's not a trick; it's a legitimate and valuable strategy.

You own a tech ETF that's down 15% from what you paid. You sell it for a $3,000 loss. You can use that $3,000 loss to offset $3,000 of capital gains from elsewhere in your portfolio. If you have no gains, you can deduct up to $3,000 of losses against ordinary income. Unused losses carry forward indefinitely.

The math is straightforward: a $3,000 loss at a 25% marginal tax rate saves you $750. That's real money.

The trap is that you usually want to stay invested in the asset class. This is where wash sales bite. Sell the losing tech ETF and immediately buy a similar but not identical tech ETF (VGT instead of QQQ, for example). You capture the loss, stay invested, and avoid triggering a wash sale because the funds are substantially different.

Tax-loss harvesting works best for taxable accounts with diversified holdings. If you hold 10 positions and three of them are down, you can harvest the losses in the three while adding to or rebalancing the others. Over time, this can add hundreds or thousands of dollars in tax savings.

The opposite move, selling winners to harvest gains, rarely makes sense. You're accelerating taxes you didn't need to pay. Instead, hold winners as long as the underlying investment thesis is intact and use the long-term capital gains rate to your advantage.

The Primary Home Exclusion: A Massive Tax Break

The IRS lets you exclude up to $250,000 of capital gains from the sale of a primary residence if you're single, or $500,000 if you're married filing jointly. This isn't some obscure loophole; it's standard tax policy.

You bought a house in 2015 for $400,000. You sell it in 2024 for $650,000. That's a $250,000 gain. If you're single and the house is your primary residence and you've owned and lived in it for at least two of the last five years, you owe zero federal capital gains tax on that $250,000. If you're married, you could have a $500,000 gain and still pay zero.

If you're a real estate investor or landlord, this doesn't apply to rental properties, only primary residences. But if you own your home, this is a massive tax advantage that tends to get buried in the fine print of real estate advice.

A Concrete Example: How Holding Period Changes the After-Tax Return

Let's say you bought Apple shares at $150 and sold them at $200. That's a $50 per share gain.

If you held the shares for six months:

  • Your $50 gain is short-term capital gains
  • You're in the 32% tax bracket
  • Federal tax: $16 per share (32% of $50)
  • State tax (varies): add another $3-5
  • You keep about $30 per share after tax

If you held the shares for 13 months:

  • Your $50 gain is long-term capital gains
  • You pay 15% federal
  • Federal tax: $7.50 per share
  • State tax: similar $3-5
  • You keep about $37-40 per share after tax

Same exact gain. Different holding period. You pocket $7-10 more per share by waiting six months. Scale that across hundreds or thousands of shares and you're talking real money.

This is why investors who treat trading as a sport often end up with worse after-tax returns than boring buy-and-hold investors. The tax drag from short-term gains offsets a lot of trading skill.

Putting It Together: A Year-End Tax Checklist

Here's how to actually optimize your cost basis and capital gains:

  1. Harvest losses before year-end: Run a report of your taxable accounts. Identify positions that are underwater. Sell the losing ones if you don't expect a rebound in the next 30 days. Use the losses to offset gains.

  2. Check holding periods on large winners: If you have a stock that's up big and it's been less than 11 months, consider whether waiting another month makes sense. The tax savings often exceed trading costs.

  3. Use specific identification: When you need to sell a security that you've bought in multiple chunks, specifically identify which shares you're selling. Prioritize selling the highest-cost basis shares first to minimize gains.

  4. Avoid wash sales: After selling a loss, don't repurchase the same or substantially identical security for 31 days. If you want exposure to that sector, buy a different ETF.

  5. Document everything: Keep records of cost basis, purchase dates, sale dates, and which specific shares you identified. Your broker usually handles this, but you should verify it in your tax records.

  6. Consider your income level for long-term gains: If you're in a year with lower income (sabbatical, career break, retirement), you might accelerate some long-term gains at a lower rate. If it's a high-income year, defer gains to the next year if possible.

The complexity of cost basis and capital gains taxation is why many investors work with an accountant or tax software. The software usually gets the math right. But understanding the mechanics means you can actually structure your trading and selling decisions to minimize taxes instead of just reacting to whatever your broker reports.

The $50 you spend on better tax software or the $500 you spend on a tax consultation often returns $2,000-5,000 in savings or avoided overpayment. That's not accounting work; that's investing in your own financial literacy.

Try the tool

Stock ROI Calculator

Put what you read into practice. Free, instant, no sign-up.

Open the Stock ROI Calculator
Share:ShareFacebookLinkedIn

Topics

capital gainstaxesinvestingcost basispersonal finance