ThomasM125
Expert Alumni

Deductions & credits

Code D in box 12 on your W-2 form is your 401-K retirement contribution, so that has nothing to do with the issue at hand. I assume you are dealing with an employee stock purchase plan. If so, depending on how long you held the stock some of the gain may be taxable as ordinary income and if so it would be reported on your W-2 form in box 1. If that happend, you can add that amount to your cost basis of the shares you sold as reported on your form 1099-B. Otherwise, your cost basis would be what you paid for the shares, which could be $0 if the company gave them to you. So, you need to scrutinize the box 1 entry on your W-2 to see if there is any additional income reflected there in addition to your gross pay. 

**Say "Thanks" by clicking the thumb icon in a post
**Mark the post that answers your question by clicking on "Mark as Best Answer"