2FA backup codes (also called recovery codes) are a set of single-use codes a service gives you when you turn on two-factor authentication, so you can still sign in if you lose your phone, security key or authenticator app. Save them when they are offered, store them offline or in a password manager away from your phone, and use one only when your normal second factor is unavailable.
Most lockouts after a lost or reset phone are avoidable with these codes. Without them, getting back in means the service's account recovery process, which is slower and depends on what the service can verify about you.
How 2FA backup codes work
When you enable two-factor authentication, the service generates a list of random codes, stores a hashed copy, and shows you the plain codes once. Later, on the sign-in screen, you choose an option such as "Try another way" or "Use a recovery code", type one code, and the service marks that code as used.
Two rules hold across services, and NIST's authentication guidelines make them requirements for any look-up secret:
- Each code works once. NIST: a look-up secret "SHALL be used successfully only once." Cross each code off as you use it.
- The service stores them hashed. NIST requires look-up secrets to be "stored in a hashed form using an approved hashing function", so the service can check a code without keeping a readable list.
Generating a new set cancels the old one at both services covered below. That is useful: if you think your codes were seen by someone else, regenerate them.
Backup codes at Google and GitHub
| Google Account | GitHub | |
|---|---|---|
| Codes per set | 10 | 16 |
| Format | 8 digits | shown when you set up 2FA |
| Single use | Yes: "After you use a backup code to sign in, that code becomes inactive." | Yes: once used, a code "cannot be reused" |
| New set cancels old | Yes | Yes |
| Where to find them | Google Account > Security & sign-in > 2-Step Verification > Backup codes | Settings > Password and authentication (in the Access section) > Recovery codes > View |
Google's codes are 8 digits, so each one is one of 108 = 100,000,000 possible values. A service that limits failed attempts, as NIST requires for look-up secrets, makes guessing one of ten valid codes hopeless; the real risk is someone finding your stored copy.
GitHub's documentation adds two useful details: you can download your recovery codes again at any point after enabling 2FA, and it recommends "saving them with a secure password manager". When you have used all 16, you generate a new list.
Where to store backup codes
The rule is simple: store them somewhere that survives losing your phone, and that a thief with your phone can't open. NIST's guidance for saved recovery codes says they should be "maintained offline (e.g., printed or written down) and stored securely by the subscriber".
| Storage | Survives a lost phone? | Risk |
|---|---|---|
| Printed, kept with important papers | Yes | Fire, or someone in the house finding it. Google suggests printing a copy. |
| Password manager entry for that account | Yes, if you can open the vault from another device | Circular if the password manager itself needs the lost phone to unlock |
| Encrypted file on a USB drive or second computer | Yes | Forgetting the file's password |
| Screenshot or note on the same phone | No | Gone with the phone, and readable by whoever has it unlocked |
| Plain text in your email | Usually | Useless if the codes are for that email account, and exposed if the email is breached |
Two copies in different places is a reasonable standard for the accounts that matter most: your primary email, password manager and bank. Keep the codes for your password manager outside the password manager, or you can lock yourself out of both at once. How password managers work explains what the vault protects and what it doesn't.
If you keep codes in a file, encrypt them first. larely's encrypt tool encrypts pasted text with a password using AES-256-GCM in your browser, without uploading it; save the encrypted output to the file and keep the password somewhere else.
How to use a backup code
- Sign in with your password as usual.
- On the two-factor screen, look for Try another way, Use a recovery code or a similar link. Google's sign-in asks you to "Enter one of your 8-digit backup codes."
- Type one unused code.
- Once you're in, cross that code off your list.
- Fix the reason you needed it: add your new phone or authenticator app, register a security key, and generate a fresh set of backup codes if you're running low or think the list was exposed.
Backup codes vs other recovery options
- A second authenticator or security key. Registering two security keys, or a passkey on two devices, is a recovery method that doesn't depend on paper. Backup codes are still worth having for when both are unavailable. Passkeys explained covers synced passkeys, which survive losing one device.
- SMS to your phone number. Convenient, but a criminal who moves your number to their own SIM receives those codes too; see what a SIM swap attack is.
- Exporting your authenticator. Some authenticator apps can back up or transfer their accounts to a new phone. Useful, but it only helps if you have the backup or the old phone, so it complements backup codes rather than replacing them.
If you're locked out without backup codes
Check first whether you still have any other registered method: a second phone, a security key, a signed-in device where the service can prompt you, or an old phone with the authenticator app still on it. If not, start the service's account recovery process from its sign-in page and expect it to ask questions about the account and to take time. Once you're back in, save a new set of codes before doing anything else. How two-factor authentication codes work explains why a new phone can't simply re-create your old authenticator codes.
Frequently asked questions
- Do 2FA backup codes expire?
- Usually not by time. Each code stops working once it has been used, and the whole set stops working when you generate a new one: Google says the old set automatically becomes inactive, and GitHub says a new set invalidates any codes generated before. Check the service's help page, because a few services handle this differently.
- Can I take a screenshot of my backup codes?
- You can, but photos usually sync to a cloud photo library and sit next to your other pictures, often protected by the same account the codes are meant to rescue. A printed copy kept with important documents, or an entry in a password manager that is itself protected separately, is safer.
- What if I lost my backup codes but can still sign in?
- Sign in now and generate a new set from the account's security settings. That invalidates the lost codes, so anyone who finds them can't use them, and gives you a fresh set to store properly.
- Are backup codes less secure than an authenticator app?
- They are a different trade-off. A backup code is long and random, so it can't realistically be guessed, but it is a static secret that works for anyone who has it, until it is used. That is why it must be stored offline or in a protected vault and treated like a spare key, not used for everyday sign-ins.