1001Ferramentas
🔄 Security

TOTP vs HOTP Comparison

Compares TOTP and HOTP characteristics in a table and shows how each derives the one-time code.

HOTP and TOTP: what actually differs

The six-digit codes in an authenticator app come out of a fairly simple algorithm: HMAC-SHA1 of a shared secret with a counter, truncated into a number. What separates HOTP from TOTP is only what goes into that counter. In HOTP it is an integer that advances on every use. In TOTP it is the clock: Unix time divided by the window size, normally 30 seconds.

That difference changes everything operationally. HOTP needs client and server to keep the same count, and a hardware token pressed inside a pocket drifts out of sync — hence the look-ahead window, where the server tries the next few codes, and the resynchronisation procedure after too many failures. TOTP has no such problem because nobody counts: both sides read the clock. In exchange, it now depends on that clock being right.

The page shows the comparison table and, in its other two modes, the step-by-step derivation of each — the dynamic truncation that takes its offset from the last nibble of the HMAC, the 0x7F mask on the first byte and the modulo by ten to the power of the digit count. It is reference material: it generates no codes and validates no secrets, it exists to show what your 2FA library is doing underneath.

Frequently asked questions

Why was my code rejected when I typed it quickly?
Most likely the device clock runs fast or slow. Servers usually accept the previous and the next window, giving roughly 30 seconds of tolerance either way; beyond that the code will not match. Turning on automatic time on the phone fixes most cases.
Is SHA-1 still used for this?
Yes, and it is the de facto standard. The known weakness in SHA-1 is collisions, which is not the attack against HMAC — HMAC-SHA1 is still considered sound for this purpose. The RFCs allow SHA-256 and SHA-512, but many authenticator apps only implement SHA-1, so switching often breaks QR code enrolment.
Can I use the same secret on two devices?
You can, and that is how backup works: the secret is the only state that matters in TOTP, so two devices holding it generate the same code. With HOTP that does not hold — each device would keep its own counter and both would drift out of sync with the server.

Related Tools