For US (which you didn't actually say but IRS implies) in addition to what Bob said:
You can choose among usually three options when you sell:
FIFO -- the oldest open lot(s)
LIFO -- the newest open lot(s)
'specific identification' -- you can choose any open lot(s). If you have only two lots, as in your example, you never need this option, because those two will be 'first' and 'last'.
But if you have say five lots purchased at different times and prices, you can choose FIFO = #1 or LIFO = #5 or you can choose #2, or #1 and #4, or #2 #3 and #5, or whatever.
The broker will usually let you make a 'sticky' setting -- "I want LIFO always" or sometimes more complicated rules maybe like "I want oldest short-term if it's a loss, otherwise newest long-term". You should always be able to make an overriding choice for a specific sale. But only at the time of the sale; you can't change this designation afterwards.
When the broker sends you (and the IRS) your 1099-B shortly after the end of the year they will include both the date and amount (called proceeds) of sale and the basis and holding period (usually purchase cost and date) of the selected lot(s) if it was/they were acquired after 2011-5 depending on type (these will be described or labelled as 'covered'). You report this information, plus any adjustments the broker didn't know about (which are rare for most people), on your tax return, specifically on form 8949 which flows to Schedule D which flows to the basic 1040. When I say 'you' it is often software you run or a preparer you hire that actually does it.
For your example, if in May 2021 you sell the Jan 2021 lot it's a short-term loss of $5. If you sell the 2020 lot and it was bought before the same day in May 2020 as the sale in May 2021, it's a long-term gain of $5, otherwise it's a short-term gain. This matters because long-term (over 1 year) gains and losses are taxed differently than short-term ones -- at least for now; Biden and the Democratic leadership are talking about proposing to change this, but it's far too soon to tell what changes if any will actually occur.