Microsoft has been changing and improving the way it handles Windows licenses. In other instances, for example if you built and installed your OS, your key is associated with your Microsoft account, so there is no way to 'lose it' anymore.
But in recent years manufacturers started storing this license within the machine's UEFI/BIOS and the information is automatically retrieved and applied when reinstalling the operating system. In brief For the longest time Windows PCs came with a product key sticker that was placed outside of the machine or with your computer's manuals.