Each purchase creates a lot. The default disposal method at most brokers is first in, first out, which sells the oldest and usually the lowest-basis shares. Specific identification lets you nominate the lot at the time of sale, and that choice controls both the size of the gain and whether it is short or long-term-capital-gains.
The instruction has to be given at or before the sale, not reconstructed afterwards, so the setting in the broker's account preferences matters more than most people realise.
Example: lots of 100 at $20, 100 at $58, and 100 at $71, with the stock at $64. Selling the $71 lot realises a $700 loss; FIFO would instead realise a $4,400 gain on the oldest lot.
Related: cost-basis, tax-loss-selling, long-term-capital-gains, wash-sale-rule, fractional-shares