Basis is what you paid, adjusted for commissions, wash-sale-rule add-backs, return of capital and corporate actions. When you own several lots of the same security, the method chosen decides which lot is deemed sold.
The main choices are fifo-cost-basis, the default at most US brokers, specific-identification-cost-basis, which gives the most control, and average-cost-basis, which is generally limited to mutual funds and some dividend reinvestment plans. Brokers report basis to the IRS on form-1099-b for covered securities, so a method chosen after the fact will not match.
This is general information for the United States, not tax advice. Rules change and depend on your circumstances, including your state and your account type; confirm anything important with a qualified tax professional.
Related: specific-identification-cost-basis, fifo-cost-basis, average-cost-basis, form-1099-b, wash-sale-rule