The two tests
An ESPP sale is a qualifying disposition only if you meet both: you held the shares more than two years from the offering (grant) date and more than one year from the purchase date. Miss either and it is a disqualifying disposition. Because the offering date is usually well before the purchase date, the two-year test is normally the binding one.
Why qualifying saves tax
In a qualifying disposition, the amount taxed as ordinary income is limited to the lesser of your actual gain or the discount measured at the offering-date price — often just the stated 15%. Everything above that is a long-term capital gain at 0/15/20%. In a disqualifying disposition, the full discount at the purchase date (which can be much larger thanks to a lookback) is ordinary income, and it is taxed the year you sell. Qualifying therefore moves more dollars to the lower rate.
The trade-off
Qualifying is not automatically better in every case. To reach it you must hold company stock for years, accepting concentration risk and market risk. If the stock falls while you wait, the tax savings can be dwarfed by the investment loss. The decision is the classic one for all equity comp: weigh a lower tax rate against the risk of holding a single stock you would not otherwise buy.
Don't forget the cost-basis fix
Qualifying or not, the same double-tax trap applies: your broker often reports only the discounted purchase price, omitting the ordinary-income portion. Adjust the basis on Form 8949 (using Form 3922) so you are not taxed twice. This matters in both dispositions.
Planning around it
If you want the qualifying treatment, track two dates per purchase lot: two years after that offering period began, and one year after the purchase. Sell only after the later of the two. Many people split the difference: sell some shares promptly to lock in the discount and limit risk, and hold a portion to a qualifying disposition when they have conviction in the stock.
A quick example
Offering price $40, purchase price $50, 15% lookback discount, so you buy at $34 and later sell at $60. Qualifying: ordinary income is the lesser of your $26/share gain or the $6 offering-date discount → $6 ordinary, $20 long-term gain per share. Disqualifying: the full $16/share purchase-date discount is ordinary income, with $10 as a capital gain. The qualifying route taxes far more of the gain at the lower long-term rate.