# What is TOTP?

> TOTP is the time-based one-time password behind authenticator apps: an HMAC of a shared secret and the 30-second step, cut to six digits. RFC 6238.

Source: https://mosaicbrowser.com/glossary/totp

## TOTP: how a six-digit code is made from a secret and the clock

TOTP, the time-based one-time password, is the algorithm behind authenticator-app codes. The site and your app share a secret; every 30 seconds each computes an HMAC of that secret and the current time step and cuts it to six digits, so the codes match without anything being sent between them.

![A new six-digit TOTP code every 30 seconds, drawn as a mosaic of tiles](https://mosaicbrowser.com/covers/totp.webp)

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](https://www.rfc-editor.org/rfc/rfc6238) (May 2011) and built on HOTP from [RFC 4226](https://www.rfc-editor.org/rfc/rfc4226) (December 2005). The recipe has four steps.

1. 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.
2. 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.
3. 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.
4. 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.

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: Logins and 2FA codes](https://mosaicbrowser.com/features/logins-and-2fa)

## 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](https://mosaicbrowser.com/guides/manage-2fa-codes-for-multiple-accounts).

![The Mosaic companion inside a profile browser: notes, saved logins and two-factor codes for that profile](https://mosaicbrowser.com/shots/companion.png)
*A live code and its countdown, inside one profile's browser*

## 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](https://mosaicbrowser.com/features/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](https://mosaicbrowser.com/features/local-first).

## Sources

1. [RFC 6238: TOTP, Time-Based One-Time Password Algorithm](https://www.rfc-editor.org/rfc/rfc6238), read November 2, 2026
2. [RFC 4226: HOTP, An HMAC-Based One-Time Password Algorithm](https://www.rfc-editor.org/rfc/rfc4226), read November 2, 2026

## Questions

### What is the difference between TOTP and HOTP?

HOTP, RFC 4226, makes a code from the secret and a counter that goes up each time a code is used. TOTP, RFC 6238, replaces the counter with the number of 30-second steps since 1970, so codes expire on their own.

### Why is my TOTP code rejected?

Usually the clock. The code depends on the time, so a phone or computer whose clock is a minute off produces codes for the wrong step. RFC 6238 recommends servers accept at most one step of network delay.

### Is TOTP more secure than SMS codes?

It cannot be intercepted in transit or redirected by a SIM swap, because nothing is sent. It can still be phished: a fake login page can ask for the code and use it within its 30 seconds.

### What is the setup key?

It is the shared secret, written in base32, which the site shows beside its QR code. The QR code holds the same secret inside an otpauth:// link. Anyone with the setup key can make your codes.

## Related

[2FA codes per browser profile, with a login vault each](https://mosaicbrowser.com/features/logins-and-2fa): Mosaic keeps 2FA codes per browser profile: each profile has its own login vault with TOTP codes, shown with a countdown and typed with real keystrokes.

[How to manage 2FA codes for multiple accounts](https://mosaicbrowser.com/guides/manage-2fa-codes-for-multiple-accounts): Keep each account's 2FA secret next to its login, back the secrets up somewhere you control, and save recovery codes before you need them.

[Browser profile: what one holds and what it shares](https://mosaicbrowser.com/glossary/browser-profile): A browser profile is its own folder of cookies, history and extensions inside one browser. Two Chrome profiles still share one fingerprint and IP.

[Local first: your profiles stay on your computer](https://mosaicbrowser.com/features/local-first): Mosaic has no cloud copy of your profiles. Profiles, cookies and proxies stay on your computer, encrypted on disk, with app lock, daily backups and a trash.

[Anti-detect browser for agencies: a browser per client](https://mosaicbrowser.com/use-cases/agencies): An anti-detect browser for agencies puts every client in its own project and every client login in its own profile, with that client's IP and 2FA codes.

[Shadowban: when a platform hides you without telling you](https://mosaicbrowser.com/glossary/shadowban): A shadowban hides or demotes an account's posts while the account still works for its owner. Platforms rarely use the word; EU law now requires a reason.

[Action block: when a platform stops one thing you do](https://mosaicbrowser.com/glossary/action-block): An action block is a temporary stop on one kind of action, such as following, liking or commenting, that a platform applies when activity looks automated.



## See TOTP on a real profile

Mosaic shows the values a site reads, per profile, and runs a leak test from inside the profile’s own page. 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.
