Sign in a Microsoft account to your Windows 10, then the Windows 10 key will be associated to that Microsoft account
After you reformat your computer and relogin the same Microsoft account, Windows 10 will automatically detect the Windows 10 key that has been associated the same account that you've used before you format
OS How to migrate windows 10 to SSD, From Hard disk to SSD