Every purchase of a stock or fund is its own tax lot, with its own cost and date. When you sell part of a holding, pick the high-cost lots you’ve held over a year. Brokers usually sell your oldest shares first, and those often cost the least, so they carry the biggest taxable gain.

Source