Common methods are first in first out, average cost, and specific identification. Selling 100 of 400 shares bought at different prices produces different taxable gains under each, and only specific identification lets the investor choose.
Example: lots of 100 shares at $20, $35 and $60, current price $58. FIFO sells the $20 lot for a $3,800 gain; specific identification can sell the $60 lot for a $200 loss. The economic position afterwards is identical.
The method must usually be elected at the time of sale and, for some fund types, cannot be changed retroactively. Basis also shifts with return-of-capital distributions and reinvested dividends, both of which are commonly missed and lead to double taxation if unrecorded.
Related: tax-loss-harvesting, return-of-capital, wash-sale-rule, tax-aware-rebalancing, asset-location