The two-factor authentication (2FA) security code lasts for 30 seconds.
If you enter the code after that time, you'll see a message saying it's expired.
When entering the code you can choose to 'remember me' which will last for 90 days on that device before needing to add the code again.