A TOTP code looks like it comes from the site. It does not. Your authenticator app makes it alone, from a secret it was given once and the current time, and the site makes the same number at the same moment. Nothing travels between them after setup, which is why the codes work in airplane mode.
How TOTP works
TOTP is defined in RFC 6238 (May 2011) and built on HOTP from RFC 4226 (December 2005). The recipe has four steps.
- Count time steps. Take the Unix time in seconds and divide by the step size, rounding down. The RFC recommends "a default time-step size of 30 seconds", so the counter goes up by one every half minute.
- HMAC it. Compute HMAC-SHA1 of that counter with the shared secret as the key. RFC 6238 also allows SHA-256 and SHA-512; most sites use SHA-1.
- Truncate. HOTP's "dynamic truncation" takes the low four bits of the last byte as an offset and reads four bytes from there, dropping the top bit.
- Cut to digits. Take that number modulo 10^6 and pad it to six digits.
Every step is public. The only secret is the key, which is why the setup key is the thing to protect: whoever has it can make your codes for ever.
What the server accepts
The server cannot know exactly when you read the code, so it compares with more than one step. RFC 6238 recommends "that at most one time step is allowed as the network delay", which in practice means a code is accepted for a little while after it rolls over. The same document covers clock drift: a server may let the counter be off by a step or two and remember the drift for that device. A code rejected over and over is usually a clock that is wrong by more than that.
Each profile keeps its own passwords and its own 2FA codesIn Mosaic: Logins and 2FA codes. A password vault and TOTP codes for each profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.
Mosaic is a desktop app
Email yourself the link and open it on your computer.
How it works: Logins and 2FA codes
How TOTP compares with other second factors
| Factor | Sent over a network | Phishable |
|---|---|---|
| SMS code | yes, to your phone number | yes, and open to SIM swap |
| TOTP | no | yes, within the code's time window |
| Push approval | yes, to the app | yes, by approving a prompt you did not start |
| Passkey or security key | no shared secret at all | no, bound to the real site's origin |
TOTP's strength is that nothing is in transit to steal. Its weakness is that it is still a number a person types, so a fake login page can ask for it and pass it on.
Where TOTP gets awkward
One person, one phone, one authenticator app works. It breaks down when the accounts are not all yours: an agency holding a client's 2FA seed, or a seller with two stores, ends up with dozens of entries in one app on somebody's phone, and a login means finding the right one and retyping six digits before the 30 seconds run out. That routine, and the alternatives to it, is set out in how to manage 2FA codes for multiple accounts.

How Mosaic handles TOTP
Mosaic keeps a credential vault per profile, and a saved login can hold its two-factor secret. The profile's Logins tab and the companion inside that profile's browser show the current code with the seconds left, and Mosaic types it into the focused field with real keystrokes (logins and 2FA shows the screens). Codes are six digits on a 30-second step with HMAC-SHA1, the defaults most sites issue. The generator is our own, about twenty lines in the main process, because a one-time-code library is the kind of dependency we do not want silently updated by somebody else.
A setup key is accepted as typed with spaces, in lowercase, or as an otpauth:// link, and it is checked when it is saved. A key that is not valid base32, or that decodes to fewer than 64 bits, is refused with the reason. That check used to run only when a code was asked for, and a mistyped key was stored and showed --- --- on its row for ever. Secrets are sealed on disk with the rest of the store, the window never receives a password, and with app lock on nothing decrypts without your password. Mosaic has no cloud copy of your profiles, and the vault is not on the list of what our server knows.
Sources
- RFC 6238: TOTP, Time-Based One-Time Password Algorithm, read November 2, 2026
- RFC 4226: HOTP, An HMAC-Based One-Time Password Algorithm, read November 2, 2026






