The tax treatment for ESPP shares is spelled out in
this IRS doc.
The holding period for favorable tax treatment lasts two years after you received the option to purchase the stock. In the case of a pretty typical ESPP with two annual periods, where you buy at the end of the six-month period based on the price at the beginning of that period, that means you need to hold for 18 months after you actually buy the stock.
What's the difference between meeting the holding period or not?
If you meet the holding period, you need to count any discount off the fair market value
as of the option grant date as regular income. Any gain above and beyond that counts as a capital gain.
If you don't meet the holding period, you need to count any discount off the fair market value
as of the stock purchase date as regular income. Any gain above and beyond that counts as a capital gain.
Note that meeting the holding period also means the capital gain portion will be long-term instead of short-term.
There are four different prices that matter for this calculation:
A = fair market price at the beginning of the offering period
B = fair market price at the end of the offering period
C = actual price you paid for the shares
D = actual price you received for the shares when you sold them
If you meet the holding period, (A-C) counts as regular income and (D-A) counts as capital gains.
If you didn't meet the holding period (B-C) counts as regular income and (D-B) counts as capital gains.
This all assumes the stock is on an upward trajectory. If any of these quantities are negative, something different happens as explained in the linked doc.
There are two dates here where the tax due on selling the shares would change. 12 months after you buy the shares, the (D-A) gain switches from short-term to long-term. Then at the end of the holding period, (B-A) of your regular income switches to a long-term gain.
Note that if you sell right away, the capital gain (D-A) will be close to zero, so let's ignore the 12-month date. The only reason you might possibly want to hold the shares for tax reasons is if you're going to hold for the full holding period to switch (B-A) from regular income to a long-term gain.
Obviously, the larger (B-A) is, the more valuable it will be to hold for the full period. However doing this means keeping some fraction of your net worth invested in the same company that signs your paychecks, which is commonly thought to be a risky proposition. You'll have to decide for yourself whether the potential tax savings is a fair compensation for that risk. My opinion is that it generally isn't. You've realized most of the special benefit of the ESPP on the day you buy the shares in the form of getting a sizable discount on the original purchase. Getting to pay slightly less tax on that discount is a much smaller benefit in comparison.
Also you should be aware that when you do sell the shares,
the 1099 your brokerage sends you will be wrong and you will need to correct your basis accordingly on your 1040 Schedule D.