
Why the Optimal Tax Lot Isn't Always the Highest-Cost Lot
Most investors who know anything about tax lot selection know one rule: sell the highest-cost lot first. The logic seems airtight. If you paid more for a share, the taxable gain is smaller. A smaller gain means less tax. Less tax is the goal. But this reasoning contains a hidden flaw, and that flaw routinely costs investors thousands of dollars on a single trade. The highest-cost lot is not always the best lot to sell. Often it isn't even close. The correct lot to sell depends on a three-way interaction between cost basis, holding period, and the investor's current tax position — and optimizing all three simultaneously is a materially different exercise than simply sorting lots by purchase price.
The method of optimal tax lot selection is the idea that every sale should be evaluated across every available lot, and the lot chosen should be the one that produces the best after-tax outcome given the full picture of the investor's tax situation this year. That's not FIFO. It's not HIFO. It's not LIFO. It's a calculation that requires knowing the investor's ordinary income, their current-year realized gains and losses, how close each lot is to the one-year holding period boundary, which bracket their gains will land in, and whether the NIIT applies. No default accounting method handles all of these inputs. They can't — default methods are rules, and rules are approximations of the optimal answer.
Why Does the Holding Period Matter as Much as Basis?
The short-term versus long-term distinction is the most important variable in tax lot selection, and it's the one most often ignored by investors focused purely on cost basis.
For 2026, a single filer in the 22% ordinary income bracket who sells a stock at a gain pays 22% on that gain if the lot is short-term, and 15% on the same gain if the lot is long-term. That's a 7-percentage-point spread, or $700 of additional tax per $10,000 of gain, purely because of when the lot was purchased. For an investor in the 32% bracket, the spread is 17 percentage points — $1,700 per $10,000 of gain. At the top of the income scale, where the 37% ordinary rate meets the 20% + 3.8% NIIT long-term rate, the spread is 20 percentage points: $2,000 per $10,000 of gain.
A holding period difference can easily dominate a basis difference. Suppose an investor holds two lots of the same stock. Lot A was purchased eleven months ago at $80 per share and is now worth $100 — a $20 short-term gain. Lot B was purchased fourteen months ago at $70 per share and is now worth $100 — a $30 long-term gain. An investor optimizing purely for basis would sell Lot A first, because it has the higher purchase price and therefore the smaller gain. But if the investor is in the 32% bracket, Lot A's $20 gain costs $6.40 in federal tax (32%), while Lot B's $30 gain costs $4.50 (15%). Selling Lot A — the "higher-cost" lot — costs $1.90 more per share. On 1,000 shares, that's a $1,900 mistake, made by following the rule that HIFO optimizes.
Wait one more month and the math inverts completely: Lot A becomes long-term, its $20 gain is now taxed at 15% for $3.00 per share, and selling it becomes the right choice. The optimal lot is not a fixed answer. It's a function of the current date, the investor's tax position, and the specific characteristics of every lot in the portfolio.
A Five-Lot Example: What FIFO, HIFO, and Optimal Selection Each Do
The following is a concrete illustration with a single stock position held in five lots. The investor is a married couple filing jointly with $280,000 in wage income and $18,000 in long-term gains already realized earlier in the year. They want to sell 500 shares. Current market price: $150 per share. Total sale proceeds: $75,000.
| Lot | Shares | Purchase Date | Cost Basis/Share | Total Basis | Holding Period | Gain/Share | Total Gain | |-----|--------|--------------|-----------------|-------------|----------------|-----------|------------| | A | 500 | 14 months ago | $90 | $45,000 | Long-term | $60 | $30,000 | | B | 500 | 8 months ago | $120 | $60,000 | Short-term | $30 | $15,000 | | C | 500 | 22 months ago | $130 | $65,000 | Long-term | $20 | $10,000 | | D | 500 | 3 months ago | $140 | $70,000 | Short-term | $10 | $5,000 | | E | 500 | 6 months ago | $155 | $77,500 | Short-term | -$5 | -$2,500 |
The couple's taxable income before this sale, after the standard deduction, is $232,000 ($280,000 wages + $18,000 LTCG already realized − $32,200 standard deduction = $265,800 — but for simplicity, let's say taxable income is $265,800). Their long-term gains are taxed at 15%. Their ordinary income is taxed at 24%. The NIIT doesn't apply because their MAGI sits below $250,000.
FIFO sells Lot A. First purchased, first sold. FIFO delivers a $30,000 long-term gain taxed at 15%. Federal tax: $4,500.
HIFO sells Lot C. Highest cost basis first. HIFO delivers a $10,000 long-term gain taxed at 15%. Federal tax: $1,500. Better than FIFO — less gain, less tax.
What would optimal selection do?
Look at Lot E. It's the only lot with an unrealized loss: −$2,500. Selling Lot E harvests a $2,500 short-term loss. Now look at Lot D: a $5,000 short-term gain. If both are sold together, the $2,500 loss offsets $2,500 of the Lot D gain, leaving a net short-term gain of $2,500. Tax at 24%: $600. Meanwhile, you've sold 1,000 shares and generated $2,500 in net gain. But the goal was to sell only 500 shares.
So: sell Lot D (500 shares, $5,000 short-term gain) and simultaneously sell Lot E (500 shares, −$2,500 loss). Net gain: $2,500, taxed at 24% = $600. But wait — we need to sell only 500 shares total, not 1,000.
Let's reset. The investor needs to raise $75,000 in cash by selling exactly 500 shares at $150. The question is which 500 shares.
- Lot E (short-term loss): Selling these 500 shares generates −$2,500 in realized losses. The investor receives $75,000 cash. The $2,500 loss offsets $2,500 of the $18,000 in long-term gains already on the books this year, saving $2,500 × 15% = $375.
- Lot D (small short-term gain): Tax at 24% = $1,200.
- Lot C (long-term, small gain): Tax at 15% = $1,500.
- Lot A (long-term, large gain): Tax at 15% = $4,500.
- Lot B (short-term, medium gain): Tax at 24% = $3,600.
The optimal lot is Lot E — the one with a loss. It's not the highest-cost lot. It's not a long-term lot. It's not even a "winner." It's the lot that turns the sale from a taxable event into a tax-reducing event. Selling Lot E delivers the same $75,000 in cash as selling any other lot, but instead of triggering a tax bill, it generates a $375 credit against the gains already realized this year.
FIFO costs $4,500. HIFO costs $1,500. Optimal selection earns $375. The difference between HIFO and optimal is $1,875 — from a single trade on a position that most investors would assume had nothing to harvest.
Why Default Methods Keep Getting This Wrong
FIFO is not designed to minimize tax. It's designed to be simple and consistent — a method that requires no judgment and produces auditable results. Brokerages default to it because the IRS accepts it, not because it's optimal.
HIFO is designed to minimize the gain recognized on each sale, which is a reasonable proxy for minimizing tax — but only when all gains are taxed at the same rate. Once holding period enters the picture, HIFO breaks down. A high-cost short-term lot can produce more tax than a low-cost long-term lot even though its basis is higher.
Specific identification — the method that lets investors choose which lot to sell — is the right tool in principle, but most investors using it manually are still optimizing on basis alone. They're doing manual HIFO. The holding period interaction, the bracket-filling effect of gains stacking on ordinary income, the current-year gain/loss position, the wash sale implications of what gets repurchased afterward — all of these require a calculation, not a rule.
This is what makes software-level lot selection different from investor-level lot selection. A human investor looking at a brokerage screen sees a sorted list of lots by cost basis or date. They pick the one that looks best. A system that evaluates all lots simultaneously, weighted by holding period, current-year tax position, bracket effects, and wash sale risk, is doing a different kind of work. The gap between those two approaches is often measured in thousands of dollars per year, compounding.
The Variables That Actually Determine the Optimal Lot
For any given sale, the optimal lot selection process has to evaluate at least five things simultaneously:
Holding period. Is the lot short-term or long-term? If short-term, is it close to crossing the one-year boundary — and if so, is the tax savings from waiting worth the market risk of holding? If a lot turns long-term in six days, waiting six days saves money at a rate of hundreds of dollars per day.
Cost basis relative to current price. The size of the gain or loss determines the absolute tax impact. A lot with a large unrealized loss may be more valuable to sell than a lot with a small gain, even if the loss lot has a lower basis.
Current-year gain/loss balance. If the investor already has $30,000 in realized short-term losses sitting on the books, a short-term gain is partially or fully offset. That changes the effective cost of realizing a short-term gain from 24% to something lower or even zero. The optimal lot changes depending on what's already been realized.
Bracket position. A gain that pushes the investor across the 0% long-term boundary into the 15% bracket is worth more to avoid than a gain that stays well inside the 15% bracket. The marginal lot matters more than the average.
Wash sale proximity. If the lot being harvested for a loss was purchased within 30 days of a repurchase of a substantially identical security, the loss is disallowed. The optimal lot to harvest is the one that delivers the most usable loss after wash sale risk is accounted for.
None of these variables is individually complicated. The complication is that all five interact, and the optimal answer is only visible when you evaluate them together, across every lot, in real time. This is an arithmetic problem, not a judgment problem — which means it's exactly the kind of problem that should be handled by software running continuously, not by an investor making a once-a-year decision with incomplete information.
For a real-world illustration of what this looks like at portfolio scale, see our FIFO vs specific identification of tax lots deep dive for more on default methods, and our capital gains tax rates 2026 explainer for the rate structure that underlies these decisions. On the income side, investors above the NIIT threshold should also read our net investment income tax NIIT 2026 piece — the holding-period spread between short and long-term widens further once the 3.8% surtax is in the picture. And for the strategic overview of how all of this adds up annually, how much can you save with tax loss harvesting walks through the compounding math.
The highest-cost lot is the right answer when all gains are taxed at the same rate, all lots have the same holding period, and there are no current-year losses to consider. In most real portfolios, none of those conditions hold. The optimal lot requires the calculation, not the rule.