Stock sales do not show on your W2. They show on a 1099-B that is issued to by the institution holding the shares. You show the gains and losses on Schedule D of the federal tax form.
You do not pay ordinary income tax on the capital gains (difference between the sales price and the purchase price).
To be honest I have never sold any of the discounted stock that I have purchased. I did work in payroll and loaded special payroll runs for discounted stock per corp directive. Most of these were because they did not meet the two year old test per the IRS. Go out to the IRS website and search for discounted employee stock and you will see the following:
I purchased stock from my employer under an employee stock purchase plan. Now I have received a Form 1099-B from selling it. How do I report this?
If the special holding period requirements described below are met, the sale of stock is treated generally as capital gain or loss. However, you may have income reportable as wages on Form 1040 if:
The option price of the stock was below the stock's fair market value at the time the option was granted, or
You did not meet either or both of the holding period requirement.
The holding period requirements are that you must hold the stock for more than 2 years from the time the option is granted to you and for more than 1 year from when the stock was transferred to you. If you do not meet either or both of these holding period requirements at the time you sell the stock, there is a disqualifying disposition of the stock. The compensation income wages that you should report in the year of the disqualifying disposition is the excess of the fair market value of the stock on the date the stock was transferred to you less the amount paid for the shares. Then increase your basis in the stock by the amount of the ordinary income before calculating your capital gain or loss.
If the holding period requirements are met, but the option exercise price is below the fair market value of the stock at the time the option was granted, you report the discount as compensation income (wages) when you sell the stock. Generally, this compensation income is the lesser of the excess of the fair market value of the stock on the date of the disposition less the exercise price OR the excess of the fair market value of the stock at the time the option was granted less the exercise price.
If the holding period requirements are met and your gain is more than the amount you report as compensation income, the remainder is a capital gain reported on Form 1040, Schedule D (PDF). If you sell the stock for less than the amount you paid for it, your loss is a capital loss, and you do not have ordinary income.
For more information, refer to Publication 525,Taxable and Nontaxable Income, and Publication 551,Basis of Assets.