The cost basis for stocks purchased over multiple years (purchase in multiple "lots") is the sum of the cost you paid for the shares you sold.
If you did not sell all your shares, you will need to select which lots you want to sell to determine your cost basis. Determining which lots to use depends on your tax situation. In general stocks purchased more than 12 months prior to selling them are taxed at a lower "long-term gains" rate.
After you determine which shares/lots you want to sell, simply add up the cost associated with purchasing those shares in those lots, and that will be your cost basis.