Join our Newsletter — 33% off our NHI Course
Home› Guides› MFA backup codes and recovery codes guide: Store,…
Guide Authentication

MFA backup codes and recovery codes guide: Store, use and design them safely

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 28 October 2026 13 min read
On this page

Backup codes and recovery codes are a second set of keys to an account protected by multi-factor authentication, and whoever holds them can sign in without your phone or security key. They exist so that losing an authenticator does not lock you out for good, but they are often saved as a text file in Downloads, emailed to oneself, or printed and forgotten, and some admin consoles can mint them for any user. This guide explains how the major services issue and replace backup codes, where to store them, what to do when you use one or suspect they have leaked, and how they are abused in account takeover. The second half is for developers and identity teams designing recovery codes: the NIST SP 800-63B Rev. 4 requirements for look-up secrets, storage, rate limits, notifications and admin controls. For help desk and identity-proofing recovery, see the Account Recovery and Help Desk Security Guide.

Key takeaways

  • A backup code is a full sign-in factor. With the password, one code gets an attacker past MFA, so protect the list like the account itself.
  • Each code works once, and a new set kills the old. Google issues 10 eight-digit codes and GitHub 16; generating a fresh set invalidates every previous code, which is the fix when a list may have leaked.
  • Store them offline or in a password manager, not next to the account they unlock. Apple warns against storing its recovery key in apps you could not open if you were locked out.
  • Some recovery choices remove the safety net. Turning on an Apple recovery key turns off Apple's standard recovery process, and GitHub Support states it will not restore access to 2FA accounts if all methods are lost.
  • Designers must treat codes as look-up secrets. NIST requires at least six decimal digits from an approved random generator, single use, hashed storage, salting for short codes, and rate limiting.

How the major services issue codes

ServiceWhat you getSingle use?Replacing themNotes from the vendor
Google AccountSets of 10 backup codes, 8 digits eachYesRefresh creates a new set and deactivates the oldDownloads are named Backup-codes-username.txt; Advanced Protection users cannot download backup codes; use "Try another way" at sign-in
Google Workspace (admin)Admins with the User management privilege can get backup verification codes for a userYesAdmin console, user, Security, 2-step verificationOnly super administrators can do this for another admin; in "Only security key" enforcement users cannot generate their own
GitHub16 recovery codesYesRegenerating cancels all previous codes; disabling and re-enabling 2FA also refreshes themView at Settings, Password and authentication; GitHub advises a secure password manager
Apple AccountOptional 28-character recovery keyReusable key, not a listReplace Recovery Key in Sign-in & SecurityTurns off standard account recovery; Apple cannot provide a lost key; recovery contact is the alternative with Advanced Data Protection

Other services follow similar patterns: a list of single-use codes shown once at MFA setup, with an option to regenerate. Check each service's own help page, because counts, formats and what regeneration does vary.

For individuals: storing and using backup codes

Where to keep them

Storage optionProtects againstRiskVerdict
Printed, in a safe place at homeOnline theft, malwareFire, loss, household accessGood for your most important accounts
Password manager entry (separate from the account's password where possible)Loss, convenienceIf the manager is compromised, codes go with it; do not store the codes for the password manager itself inside itGood for most accounts; GitHub recommends it
Text file in Downloads or desktopNothing muchInfostealer malware collects files and browser data from infected devicesAvoid: move it, then delete the file
Email to yourself or cloud notesLossAnyone in your mailbox gets your MFA bypass; you may not reach the notes if locked outAvoid; Apple warns against storing its recovery key in Notes, Passwords, iCloud Photos or iCloud Drive
Photo on your phoneNothing if the phone is lostLost with the phone; synced to cloud photosAvoid

The account to plan first is your main email, because it resets everything else. Keep its backup codes offline. See the Personal Account Recovery Planning Guide.

When you use a code

  1. Sign in using the backup code option (on Google, "Try another way").
  2. Cross off or delete the code you used: it will not work again.
  3. If you used it because you lost your phone or key, enrol a replacement authenticator straight away, then remove the lost one from the account.
  4. If you are running low, generate a new set and store it; the old codes stop working.

If you think your codes leaked

  1. Sign in and generate a new set immediately, which invalidates the old list on Google and GitHub.
  2. Change the password, because codes are only useful with it.
  3. Sign out other sessions and review recent sign-in activity, connected apps and recovery email and phone.
  4. If the file was on a computer that might have malware, clean or rebuild it before generating new codes there. See the Infostealer Threat Guide.

Backup codes compared with other recovery methods

Codes are one option among several. NIST SP 800-63B encourages subscribers to keep at least two separate means of authentication, and notes that look-up secrets or an additional out-of-band device can be issued for use if the main authenticator is lost, stolen or damaged. The best setup combines two or three of the following.

MethodPhishing-resistant?Survives losing your phone?Main riskBest use
Backup or recovery codesNo: a fake page can ask for oneYes, if stored away from the phoneTheft of the stored listLast-resort fallback on every account that offers them
Spare security key or second passkey on another deviceYesYesLosing both devices togetherEmail, admin and finance accounts
Authenticator app backup or syncNoYes, once restored to a new phoneWeak protection of the backup; OWASP notes TOTP seeds may be stored insecurelyConvenience for many low-risk accounts; GitHub lists TOTP app backups among recovery options
SMS to a phone numberNoOnly if the number is moved to a new SIMSIM swap, which OWASP highlights as a reason SMS is weak for recoveryAvoid as the only fallback
Recovery contact (trusted person)Depends on the serviceYesSocial engineering of the contactApple accounts with Advanced Data Protection, as an alternative to a recovery key
Vendor account recovery processNoYes, slowlyWeakest link if it accepts easily found factsSafety net; GitHub's process uses verified devices, SSH keys or tokens and takes up to three business days

A simple recovery kit

For each account that matters (main email, Apple, Google or Microsoft account, password manager, bank, work admin), record on paper: the account name, which authenticators are enrolled, where the backup codes or spare key are kept, and the date the codes were last regenerated. Keep the sheet with the printed codes in a secure place at home, and review it once a year or whenever you change phone. The point is that when a phone is lost or broken, nothing on the recovery path depends on that phone. A password manager's own recovery codes or emergency kit belong on that paper sheet, never inside the manager. Organisations can give staff the same template for work accounts, minus the codes themselves, which should go through the help desk's verified process instead.

How backup codes are abused

  • Stolen code files: a downloaded code file sitting on disk is collected along with saved passwords by malware, giving an attacker both factors at once.
  • Codes generated after takeover: an attacker with a hijacked session can often view or generate backup codes, creating a way back in that survives the victim changing their phone. OWASP's MFA guidance is to require reauthentication with an existing factor for changes like this, not just a live session. See the Session Hijacking and Cookie Theft Guide.
  • Admin-issued codes: in Google Workspace, an admin with User management can get backup codes for a user; a compromised or socially engineered admin can therefore sign in as staff. Restrict that privilege and review its use.
  • Phished codes: fake sign-in pages ask for "a backup code" as readily as for a one-time password. A backup code is not phishing-resistant.
  • Help desk pressure: callers claiming to have lost both phone and codes push support staff into weaker resets. See the Account Recovery and Help Desk Security Guide.

For developers: designing recovery codes

Backup codes are what NIST SP 800-63B Rev. 4 calls look-up secrets. Its requirements, and the OWASP Multifactor Authentication Cheat Sheet, give a clear design.

Design pointRequirement or practiceSource
Length and randomnessAt least six decimal digits (or equivalent), generated with an approved random bit generator; longer codes (for example 8 to 10 characters, or alphanumeric) add marginSP 800-63B 3.1.2.1
Single useEach secret SHALL be used successfully only onceSP 800-63B 3.1.2.2
StorageStore hashed with an approved hash; codes with under 112 bits of entropy must also be salted with at least a 32-bit salt; never store plaintextSP 800-63B 3.1.2.2
Rate limitingLimit failed attempts effectively, as for other authenticatorsSP 800-63B 3.1.2.2 and 3.2.2
Issue at enrolmentOffer several single-use codes when the user sets up MFAOWASP MFA Cheat Sheet
Encourage a second authenticatorSHOULD encourage at least two separate means of authentication so codes are a last resortSP 800-63B
RegenerationGenerating a new set invalidates every unused code from the old set; require reauthentication with an existing factor firstGoogle and GitHub behaviour; OWASP
NotificationNotify out of band when a code is used, when codes are viewed or regenerated, and when factors changeOWASP MFA Cheat Sheet
No downgradeDo not let recovery fall back from a phishing-resistant authenticator to a weaker method unless policy requires itOWASP MFA Cheat Sheet

Implementation steps

  1. Generate: create 10 to 16 codes with a cryptographically secure generator; show them once with download, print and copy options and a clear warning.
  2. Store: hash each code with a salt; keep a used flag per code; never log codes.
  3. Verify: compare in constant time, mark used on success, and apply the same lockout and rate limits as for other factors.
  4. After use: show remaining count, prompt the user to enrol a replacement factor, and notify them by email or push.
  5. Regenerate: require a fresh MFA check, invalidate the old set atomically, notify.
  6. Test: confirm reuse fails, regenerated sets invalidate old codes, rate limits apply to code entry, and codes never reach logs or analytics.
  7. Roll back: if changing code format, accept old-format codes until users regenerate, rather than invalidating existing codes silently.

Decision guidance

  • Consumer service: backup codes plus a second authenticator (passkey on another device) is a sound default; avoid SMS-only recovery because of SIM swap risk, which OWASP highlights. See the SIM Swap Fraud Guide.
  • Workforce identity: prefer two registered phishing-resistant authenticators per person and an identity-verified help desk process; if codes are allowed, restrict who can generate them for others.
  • High-value accounts (admins, finance): use security key only enforcement where available; Google notes users in "Only security key" mode cannot generate their own backup codes, so plan a spare key per admin instead. See the Admin panels and super admin accounts.
  • Self-custody options like Apple's recovery key: suit users who accept permanent lockout risk in exchange for removing the vendor's recovery path.

Where identity fits

Shared mailboxes and service accounts sometimes have MFA enrolled by one person, with the backup codes stored in a team wiki so others can sign in. That turns a non-human or shared account into an unattributed one with a static bypass secret. Move these accounts to proper service identities or delegated access, and if a shared account must remain, vault its codes with access logging and rotate them when anyone with access leaves. See the Top 10 MFA Mistakes.

Detection and measurement

  • Sign-ins by backup code: alert when a backup code is used from a new device or location, especially for admins.
  • Code generation events: alert on backup code generation or viewing shortly after a password reset or a sign-in from a new location, and on any admin generating codes for another user.
  • Factor changes: MFA method added or removed within the same session as a backup code sign-in is a takeover pattern.
MetricTarget
Users with at least two registered authenticatorsRising; 100% for admins
Admin-generated backup codes per month, each with a ticketLow, 100% ticketed
Backup code sign-ins followed by new factor enrolment within 24 hoursHigh (shows users replace lost factors)
Backup code sign-ins from unfamiliar locations investigated100%
Help desk MFA resets per 1,000 usersFalling as self-service recovery improves

Common failure patterns

  • Code file left in Downloads: the default download name makes it easy for malware or anyone with access to find.
  • No regeneration after suspected exposure: old codes stay valid until a new set is created.
  • Generating codes with only a session: no reauthentication lets a hijacked session mint persistence.
  • Broad admin rights to mint codes: every admin with user management can sign in as staff.
  • Plaintext storage server-side: a database leak exposes every user's MFA bypass.
  • Codes as the only backup: users lose the paper and phone together; encourage a second authenticator.

Framework mapping

FrameworkReferenceRelevance
NIST SP 800-63B Rev. 43.1.2 Look-Up Secrets; 3.2.2 Rate LimitingCode generation, storage, single use, attempt limits
NIST SP 800-53 Rev. 5IA-5 Authenticator Management; IA-2(1) multi-factor authentication to privileged accountsIssuing and protecting authenticators
NIST CSF 2.0PR.AA-01 identities and credentials managed; PR.AA-03 users authenticatedCredential lifecycle
MITRE ATT&CKT1111 Multi-Factor Authentication Interception; T1556.006 Multi-Factor Authentication; T1539 Steal Web Session CookieCapturing codes, tampering with MFA settings, session theft that leads to code generation

Practitioner checklist

  • Store backup codes for email and admin accounts offline, never in the same mailbox or notes they protect.
  • Delete code files from Downloads and desktops after moving them.
  • Regenerate codes after any suspected exposure or device infection.
  • Encourage or require a second authenticator so codes are a last resort.
  • Require reauthentication with an existing factor before codes are viewed or regenerated.
  • Hash and salt codes server-side, enforce single use and rate limits.
  • Notify users out of band on code use, regeneration and factor changes.
  • Restrict which admins can generate codes for other users and alert on it.
  • Give admins spare security keys instead of codes where security key only mode is enforced.

Standards and references

Related NHI Mgmt Group resources: Account Recovery and Help Desk Security Guide · Personal Account Recovery Planning Guide · Top 10 MFA Mistakes · Phishing-Resistant MFA Guide

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 28 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org