Direct answer: Capital gains tax in practice involves four decisions: determining whether a gain is short-term or long-term by counting the exact holding period, choosing which tax lots to sell using specific identification to minimize current-year tax, offsetting gains with harvested losses where available, and evaluating when account location shifts a taxable gain into a tax-deferred or tax-free wrapper. The examples below walk through each decision with numbers.

Capital Gains Tax in Practice: Worked Examples and Portfolio Context

By Swoopr Editorial Team

Published

AI-assisted content · Swoopr Investment is responsible for the final published article.

Example 1: Basic Gain Calculation and Holding Period

An investor buys 100 shares of a stock at $40 per share on March 1, 2024. They sell all 100 shares at $65 per share on March 15, 2025. The holding period runs from March 2, 2024 (the day after purchase) through March 15, 2025 (the day of sale), totaling 379 days. Since 379 days exceeds 365, the gain qualifies as long-term.

The gain calculation: 100 shares at $65 = $6,500 proceeds minus 100 shares at $40 = $4,000 cost basis equals a $2,500 long-term gain. If this investor has total taxable income of $85,000 (single filer), the applicable federal long-term capital gains rate is 15%. Federal tax owed: $2,500 times 15% = $375.

Contrast this with the same investor selling on February 28, 2025 instead, one day before crossing the one-year mark (364 days held). The gain is identical at $2,500, but it is now short-term. At a marginal ordinary income rate of 22%, the tax becomes $2,500 times 22% = $550, an increase of $175 simply from selling one day too early. On a $100,000 gain instead of $2,500, that same one-day difference at these rates would cost $1,750 in additional tax.

The Exact Holding Period Counts

The IRS counts the holding period from the day after the trade date of purchase through the trade date of sale, inclusive. For exchange-traded securities, the relevant date is the trade date, not the settlement date. If you buy on December 31, 2024, your holding period begins January 1, 2025. You must sell on or after January 1, 2026 (not December 31, 2025) to qualify for long-term treatment. Calendar-aware tracking tools or a simple spreadsheet with the trade date plus 366 days will identify the exact date for any position.

Example 2: Lot Selection Using Specific Identification

An investor holds 300 shares of the same ETF purchased in three separate lots:

Three tax lots of the same ETF with different purchase dates and cost bases.
Lot Purchase Date Shares Cost Basis per Share Current Price Gain/Loss per Share Holding Period
A Jan 5, 2023 100 $50 $80 +$30 Long-term
B Jul 10, 2024 100 $70 $80 +$10 Short-term
C Mar 1, 2025 100 $85 $80 -$5 Short-term

The investor needs to sell 100 shares to fund a home purchase. Using FIFO (the default), they would sell Lot A: 100 shares at a $30 per-share long-term gain, generating $3,000 of long-term capital gain. At 15%, federal tax = $450.

Using specific identification, the investor has three alternatives:

If the investor has other realized gains this year that need offsetting, selling Lot C to harvest the $500 loss is the best choice: it generates a $500 deduction while keeping the other lots intact. If cash is needed and no loss harvesting benefit exists, selling Lot B generates $1,000 of short-term gain but a lower immediate tax bill ($220 vs $450) than FIFO. The optimal choice depends on the investor's broader tax picture for the year.

Example 3: Tax-Loss Harvesting Calculation

An investor holds two positions in early December 2025. Position X has a $12,000 long-term gain. Position Y has a $4,000 short-term loss. The investor plans to sell X to rebalance and wants to understand how Y affects the tax outcome.

Without harvesting Y: $12,000 long-term gain at 15% = $1,800 federal tax.

With harvesting Y: the $4,000 short-term loss first offsets up to $4,000 of the long-term gain. Remaining long-term gain: $12,000 minus $4,000 = $8,000. Tax on remaining gain: $8,000 times 15% = $1,200. Tax savings from harvesting: $1,800 minus $1,200 = $600.

Note the ordering: capital losses offset capital gains in a specific sequence. Short-term losses first offset short-term gains; long-term losses first offset long-term gains. Excess short-term losses then offset long-term gains, and vice versa. In this example, the short-term loss from Y offsets the long-term gain from X because there are no same-character gains available, reducing the more favorably taxed long-term gain. The IRS does not let you choose; the offset sequence is mandatory.

The Wash-Sale Rule Complicates Harvesting

If the investor sells Position Y at a loss and buys the same or a substantially identical security within 30 days before or after the sale (the wash-sale window), the IRS disallows the loss. The disallowed loss is added to the cost basis of the repurchased shares rather than disappearing permanently. A common harvesting approach: sell Y on December 5, purchase a similar but not substantially identical ETF to maintain market exposure (for example, selling a total market ETF and buying a broad market index ETF tracking a different index), and wait 31 days to repurchase the original security if desired.

Example 4: Full Portfolio Tax-Impact Assessment

Consider a $500,000 taxable portfolio for a married filing jointly investor with $180,000 in other income (salary, interest, dividends). The investor is evaluating a year-end rebalance that would require selling positions with aggregate gains and losses as follows:

Proposed year-end rebalance: positions to sell with gain/loss classification.
Position Type Gain/(Loss)
Large-cap equity ETF (Lot A)Long-term gain+$25,000
International ETF (Lot B)Long-term gain+$8,000
Tech sector ETFShort-term gain+$6,000
Bond ETFShort-term loss-$3,500
Small-cap ETF (Lot C)Long-term loss-$4,000

Step 1: Net the gains and losses by type.

Step 2: Total taxable income after rebalance = $180,000 plus $2,500 short-term gain plus $29,000 long-term gain (for rate determination purposes, $180,000 ordinary income and $29,000 long-term). The short-term gain of $2,500 is added to ordinary income and taxed at 22%. The $29,000 long-term gain is taxed at 15% (the income plus long-term gains does not push above the $583,750 married filing jointly threshold for the 20% rate).

Step 3: Calculate tax. Short-term gain tax: $2,500 times 22% = $550. Long-term gain tax: $29,000 times 15% = $4,350. Total federal capital gains tax from the rebalance: $4,900.

Step 4: NIIT check. Modified AGI = $180,000 plus $2,500 plus $29,000 = $211,500. This exceeds the $250,000 married filing jointly NIIT threshold? No, $211,500 is below $250,000. No NIIT owed. If instead the ordinary income were $225,000, then MAGI would be $256,500, and NIIT would apply to net investment income: ($2,500 plus $29,000) times 3.8% = $1,197 additional tax.

Account Location: Moving Gains into Tax-Advantaged Accounts

The most powerful capital gains tax tool is account location: holding assets that generate taxable gains inside tax-advantaged accounts where gains are deferred or eliminated.

A high-turnover fund that generates frequent short-term capital gain distributions belongs in a tax-deferred traditional IRA or 401(k), where no tax is owed on internal gains until withdrawal. Holding the same fund in a taxable brokerage account means paying ordinary income tax on every distribution. A buy-and-hold equity ETF that generates infrequent long-term gains can reasonably stay in the taxable account and take advantage of the preferential long-term rate and eventual step-up in basis at death.

This analysis changes for Roth accounts. Inside a Roth IRA, all gains are permanently tax-free, making it the ideal location for the highest-expected-return assets in the portfolio, typically equities. Placing bonds or cash equivalents in a Roth wastes the tax-free space on lower-returning assets.

Frequently Asked Questions

How do I calculate my capital gains tax on a stock sale?

To calculate capital gains tax: subtract your adjusted cost basis from the sale proceeds to get the gain. Determine whether the gain is short-term (held 365 days or fewer) or long-term (held more than 365 days). Apply the applicable rate: for short-term gains, use your ordinary income marginal rate (10% to 37%); for long-term gains, use 0%, 15%, or 20% based on your total taxable income. If your modified AGI exceeds $200,000 (single) or $250,000 (married filing jointly), add 3.8% NIIT. Example: $10,000 long-term gain for a single filer with $80,000 taxable income means $10,000 times 15% = $1,500 federal tax.

Does tax-loss harvesting always save taxes?

Tax-loss harvesting saves taxes only in the year the loss is realized. The loss offsets gains dollar for dollar and can offset up to $3,000 of ordinary income annually if gains are insufficient. However, selling at a loss resets your cost basis to the lower sale price, so future appreciation on the replacement position generates a gain taxed when you eventually sell. The net benefit is deferral, not permanent elimination, unless you hold the replacement until death to trigger the step-up in basis or donate it to charity.

What is specific identification and when should I use it?

Specific identification lets you choose exactly which tax lots you sell, rather than defaulting to FIFO (oldest shares first). Use it when you have multiple lots with different cost bases and different holding periods. To minimize current-year gain, sell the highest-basis lots first. To maximize a loss harvest, sell the lowest-basis lots. To qualify for long-term rates, sell lots that have crossed the one-year threshold. Most major brokers support specific identification, but you must elect it at or before the time of the sale, not after. A post-sale attempt to reassign which lot was sold does not satisfy the requirement.

References