
What Is Tax Lot Optimization? The Hidden Variable Inside Every Sale
Every time you sell shares of a stock or fund you have bought more than once, you face a decision that most investors do not realize they are making. Which shares, exactly, are you selling? The ones you bought three years ago at $80? The ones you bought last spring at $140? The ones you bought in December at $112?
The answer determines your cost basis, which determines your gain or loss, which determines your tax bill. Two investors who own identical positions in the same stock, sell the same number of shares on the same day at the same price, and end up in completely different tax situations — because they sold different lots. This is tax lot optimization: the practice of choosing deliberately which specific shares to sell in order to produce the most favorable tax outcome.
It sounds like a technical detail. It is actually one of the highest-leverage decisions in portfolio management.
What a tax lot is
A tax lot is a record of a specific purchase of a security — the date, the number of shares, and the price paid. Every time you buy shares of the same security, you create a new lot. If you bought 50 shares of an S&P 500 ETF in January 2022, another 50 shares in July 2022, and another 50 shares in March 2023, you hold three separate tax lots, each with its own cost basis and holding period.
When you sell shares, the IRS requires you to match the shares sold against specific lots. The lot you designate determines two things simultaneously: the size of your gain or loss, and whether that gain or loss is short-term (held one year or less, taxed as ordinary income) or long-term (held more than one year, taxed at preferential rates). Both matter enormously to the final tax outcome.
The default that costs investors money: FIFO
If you do not tell your broker which lots to sell, most brokerages default to FIFO — first in, first out. The shares you purchased earliest are treated as the ones sold first. This is a reasonable accounting convention, but it is almost never the optimal choice for a taxable investor.
FIFO systematically delivers the worst tax outcome in two common situations. The first is a rising market: your oldest shares typically have the lowest cost basis and therefore the largest embedded gain. Selling them first maximizes your taxable gain. The second is a transition from short-term to long-term holding: if you have been accumulating shares regularly, your oldest lots have aged past the one-year threshold while newer lots are still short-term. FIFO sells the long-term lots first, which sounds good, but it leaves the high-basis short-term lots untouched — when what you often want is to sell the highest-cost lots regardless of their holding period.
Specific identification: the method that puts you in control
The IRS permits an alternative called specific identification — or spec ID — which allows you to designate exactly which lots you are selling at the time of each transaction. Your broker records the instruction, and those specific shares are treated as the ones sold.
Specific identification gives you complete control over three variables simultaneously: the size of the realized gain or loss, the character of that gain or loss (short-term vs long-term), and which lots remain in your portfolio for future management. Used well, it turns every sale into a tax decision rather than an accounting default.
The instruction must be given at or before the time of the sale. You cannot retroactively reassign lots after the transaction settles. Most major brokerages support specific identification through their online interfaces, though the process varies — some require you to call, some have a dropdown at the point of sale, and some require a written instruction submitted in advance.
The four lot selection strategies and when to use each
There is no single correct way to select lots. The optimal choice depends on your tax situation in the current year, your expected future tax rates, the composition of your portfolio, and your long-term investment plans. But there are four core strategies that cover most situations.
Highest cost first (HIFO). Sell the lots with the highest cost basis first, regardless of holding period. This minimizes the realized gain on any given sale. It is the right default for most investors who simply want to reduce current-year taxes on a planned sale. If you need to raise $50,000 from a position, selling the highest-cost lots means recognizing the smallest possible gain from that transaction.
Tax loss harvesting lots. Sell specifically the lots that are currently showing a loss — below their original purchase price — to realize a capital loss for tax purposes. This is the foundation of tax loss harvesting: identifying which lots within a position are underwater and selling those while leaving the profitable lots intact. The replacement purchase resets the cost basis on those shares while maintaining your overall exposure to the asset.
Long-term lots for planned gains. When you need to realize a gain — for rebalancing, for liquidity, or for estate planning — selling lots held more than one year ensures the gain is taxed at long-term rates (0%, 15%, or 20%) rather than short-term ordinary income rates (up to 37%). For an investor in the top bracket, the difference between short-term and long-term treatment on a $100,000 gain is $17,000 in federal tax.
Holding period engineering. Sometimes the most valuable move is to wait. A lot purchased eleven months ago will become long-term in one more month. Selling it now costs the short-term rate; waiting 31 days costs the long-term rate. For a large position, the tax saved by waiting a few weeks can be significant. Lot-level tracking makes this visible; without it, you are managing in the dark.
A concrete example: three lots, three outcomes
Suppose you own 300 shares of a technology ETF, purchased in three tranches over three years, and you want to sell 100 shares today at the current price of $180.
- Lot A: 100 shares purchased 3 years ago at $90. Long-term gain of $9,000 if sold.
- Lot B: 100 shares purchased 18 months ago at $150. Long-term gain of $3,000 if sold.
- Lot C: 100 shares purchased 8 months ago at $200. Short-term loss of $2,000 if sold.
Under FIFO, you sell Lot A — recognizing a $9,000 long-term gain. At a 20% federal rate plus 3.8% NIIT, you owe $2,142 in federal tax on that sale.
Under HIFO, you sell Lot C — recognizing a $2,000 short-term loss. Not only do you owe nothing, you have created a $2,000 tax asset that offsets other gains.
The difference between those two outcomes on a single 100-share sale: $4,142 in after-tax value — from a decision that took thirty seconds and required no change to your investment position whatsoever. You still own 200 shares of the same ETF. The only thing that changed was which shares you told your broker to sell.
Why lot optimization compounds over time
The impact of individual lot selection decisions seems modest in isolation. Over a decade of regular investing, buying and selling across a portfolio of twenty or thirty positions, each with multiple lots, the cumulative effect is substantial.
Every time you sell the highest-cost or loss lots instead of defaulting to FIFO, you are preserving your lowest-cost lots inside the portfolio. Those low-basis lots represent an embedded tax liability that you are not yet required to pay. The longer they stay invested, the longer that deferred tax bill is working for you — compounding returns on money that would otherwise have gone to the IRS.
Investors who actively manage their lot selection over ten years tend to accumulate portfolios with significantly lower embedded gain ratios than investors who default to FIFO. This is not because they sold more or less — it is because they were strategic about which shares left the portfolio and which stayed. The result is a portfolio with a higher effective cost basis, less future tax exposure, and more capital available for continued compounding.
The scale problem: why this is hard to do manually
Tax lot optimization is conceptually simple. Executed manually across a real portfolio, it becomes genuinely difficult.
A portfolio of 25 positions, each built up through three years of regular contributions plus dividend reinvestment, might contain 150 to 200 individual tax lots. Every time you want to sell anything, the optimal lot choice depends on: the current unrealized gain or loss in each lot, the holding period of each lot, your total realized gains and losses so far this year, your expected income and tax rate, whether a wash sale has recently occurred in that security, and what lots you plan to sell or harvest later in the year.
Tracking all of that manually — across a taxable account, an IRA, a spouse's accounts, and an employer 401(k) — is not realistically possible with a spreadsheet and a December review. It is a continuous data problem that requires continuous monitoring.
This is the same reason that sophisticated tax management has historically been available only to wealthy investors with access to institutional systems. The strategy — sell the right lots at the right time — is straightforward. The execution, at the speed and precision required to capture the full benefit, requires infrastructure that was not accessible to individual investors until recently.
The practical starting point
If you are not currently using specific identification, the first step is to change your default with your brokerage. Most major brokerages allow you to set specific identification as the account-level default for new purchases. Doing so does not require any immediate sales — it simply ensures that future transactions are governed by your instructions rather than FIFO.
The second step is to understand your current lot structure. Most brokerage platforms will show you cost basis detail by lot under their tax or performance sections. Reviewing this before any planned sale — even a quick scan — often surfaces the obvious wins: a lot purchased at a much higher price, a lot very close to the one-year mark, a lot currently at a loss that could be harvested rather than sold at a gain.
The third step, for investors with larger and more complex portfolios, is to consider whether the manual approach is capturing the full opportunity — or whether continuous, automated lot-level monitoring would produce meaningfully better outcomes. For most investors who have been defaulting to FIFO for years, the answer is almost always the latter.