Two-Factor Codes Explained: How TOTP Authenticator Apps Work
Security · Published October 18, 2026 · Updated October 24, 2026 · 3 min read
Written by Akinrinmade Michael · General information, not professional advice
When a site asks for a six-digit code from an app, it's using a time-based one-time password, or TOTP. The code proves you hold something only you should have, which is a phone or an app with a secret in it. A stolen password alone isn't enough to get into your account.
Why a second factor helps
Passwords leak. They get reused, guessed, phished and dumped in data breaches. A second factor means the attacker also needs something you have. Codes sent by text message are better than nothing, but they can be redirected by a SIM swap, where someone talks your phone company into moving your number. A TOTP code is made on your device and never travels over the phone network, so that attack doesn't work on it.
How a code is made
The site and your app share a secret key when you set up two-factor sign-in. Every 30 seconds, both do the same four things:
- Take the current time and work out which 30-second step it falls in. That step number is the counter.
- Mix the counter with the secret using a keyed hash called HMAC.
- Cut a number out of the result, using a fixed rule for where to start.
- Keep the last six digits.
Because both sides have the same secret and the same clock, they get the same code, and nothing is sent between them. This is a public standard, RFC 6238, so any authenticator app works with any site that follows it. The TOTP Generator runs these steps in your browser and shows the countdown to the next code.
The secret key
The secret is usually shown as a string of capital letters and the digits 2 to 7. That's Base32, chosen because it's easy to read and type without mixing up look-alike characters like 0 and O. The guide to Base32 and Base64 explains why. Whoever has the secret can make your codes, so keep it as private as a password.
Setting one up
Most sites show a QR code. It holds an otpauth link with the secret, the account name and the settings. Scanning it saves you from typing. If you can't scan, the same screen usually has a "show the key" option, and you can type that into the app instead.
otpauth://totp/Example:ada@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Example&period=30&digits=6
The QR Code Generator can turn a link like that into a scannable image, which is handy for testing a login system you're building. The guide on how QR codes work covers what's inside them.
Which app to use
| Option | Backs up codes? | Notes |
|---|---|---|
| Google Authenticator | Yes, to your Google account | Simple and widely supported |
| Microsoft Authenticator | Yes, to your Microsoft account | Also approves Microsoft sign-ins with one tap |
| Authy | Yes, encrypted with a password | Works on several devices |
| Password manager (1Password, Bitwarden) | Yes, with your vault | Fills codes in for you, but puts both factors in one place |
| Hardware key | Not applicable | Strongest against phishing, costs money |
Pick one that backs up. If a phone with the only copy of your secrets falls in a lake, you want a way back in.
Why a code sometimes fails
- The clock on your phone is wrong. Turn on automatic time. A few seconds off is usually tolerated, a minute isn't.
- You typed the code just as it changed. Wait for the next one.
- The site uses different settings, such as 8 digits or a 60-second step. A scanned QR code handles this for you.
- You're using the wrong account's entry in the app, which is easy to do when several accounts share a name.
What TOTP doesn't protect against
A fake login page can ask for your password and your code, and pass both to the real site in the few seconds the code is valid. That's phishing in real time. Check the address before you type a code, and for your most important accounts consider a hardware key, which only answers the real site.
Keeping it safe
- Save the backup codes the site gives you, and store them offline.
- Keep the secret in a real authenticator app or password manager.
- Don't paste a secret you care about into a web page you don't control. Close the generator page when you're done.
- Before getting rid of an old phone, move your codes to the new one first.