Learn
HOTP vs TOTP
HOTP vs TOTP comes down to one input: HOTP hashes a counter that moves when a button is pressed, TOTP hashes the number of 30-second steps since 1970, so only TOTP codes expire.

HOTP and TOTP make a code from the same secret key with the same HMAC function; only the counter differs. HOTP (RFC 4226, December 2005) counts button presses. TOTP (RFC 6238, May 2011) counts 30-second steps since 1 January 1970 UTC. That one input explains why only TOTP codes expire.
Try both on the RFC key
HOTP token counter
Press the button to show the code for counter 0.
TOTP clock 30 s steps
Move the slider to change the time.
Server look-ahead window s = 5
Server counter C = 0. It tests counters 0 to 4.
Press the token, then send its code.
The same RFC test key gives the same codes in HOTP and TOTP
Both codes below come from the key 12345678901234567890, the test key in both RFCs.
| HOTP counter | HOTP code (6 digits) | TOTP seconds that use this counter |
|---|---|---|
| 0 | 755224 | 0 to 29 |
| 1 | 287082 | 30 to 59 |
| 2 | 359152 | 60 to 89 |
| 3 | 969429 | 90 to 119 |
| 4 | 338314 | 120 to 149 |
| 5 | 254676 | 150 to 179 |
| 6 | 287922 | 180 to 209 |
| 7 | 162583 | 210 to 239 |
| 8 | 399871 | 240 to 269 |
| 9 | 520489 | 270 to 299 |
The two standards meet at one point. At 59 seconds the TOTP counter is 1. RFC 6238 Appendix B lists the eight-digit code 94287082 for that time, and its last six digits are 287082, the HOTP code for counter 1 in the table. TOTP is HOTP with the clock supplying the counter.
The same holds later in the RFC 6238 table. At 1111111109 seconds the step is 37037036 and the eight-digit code is 07081804. To try your own key, use the TOTP generator.
HOTP vs TOTP side by side
They differ in where the counter comes from, how long a code lives and what the server keeps.
| HOTP | TOTP | |
|---|---|---|
| Counter | An integer kept on the token and on the server | Whole time steps since the Unix epoch, 30 seconds by default (RFC 6238 section 4) |
| Who advances it | The token on each press; the server only after a successful check | The clock |
| Code lifetime | Until the server counter passes it; RFC 4226 sets no time limit | One time step, plus the grace the verifier allows |
| Server stores | The secret and a counter per token | The secret; optionally the drift seen for each token |
| Resynchronization | Look-ahead window s (RFC 4226 section 7.4) | Neighboring steps are accepted; drift can be recorded and corrected (RFC 6238 sections 5.2 and 6) |
| Reuse | A matching code moves the counter past it | The verifier must not accept the same code twice (RFC 6238 section 5.2) |
| Standard | RFC 4226, December 2005 | RFC 6238, May 2011 |
Why only TOTP codes expire
A time step ends by itself. A counter waits for a press.
TOTP: the clock moves the counter. On the RFC key, the code at 29 seconds is 755224. Two seconds later the step changes and the code is 287082. Nobody pressed anything.
HOTP: only a press moves the counter. The first press shows 755224. After ten minutes or three days without a press, the token still shows 755224, and the server accepts it until its counter passes it.
The calculation behind both codes, step by step, is in what is an authenticator app.
When token and server disagree
A token counter can run ahead of the server. HOTP closes the gap by looking ahead.
The server counter rises only after a good code (RFC 4226 section 7.2). The token counter rises at every press, so a few presses that were never sent leave the token ahead. With a look-ahead window s, the server accepts counters C to C + s - 1 (RFC 4226 Appendix E.4) and then sets its counter one past the match.
- Server counter C
- 0
- Look-ahead window s
- 5
- Counters tested
- 0 to 4
- Digits
- 6
| Code entered | Token counter | Verdict | Server counter afterwards |
|---|---|---|---|
| 338314 | 4 | Accepted | 5 |
| 254676 | 5 | Refused | 0 |
| 755224 | 0 | Accepted | 1 |
Each row starts at server counter 0.
TOTP shifts by whole steps instead. RFC 6238 section 5.2 has a verifier allow at most one step of delay, and section 6 lets it record a token’s drift and correct for it.
What neither one stops
Both are typed codes. Anyone who learns one inside its window can use it.
- Relay attack. A fake sign-in page forwards the typed code at once. NIST SP 800-63B-4, section 3.1.4, states that OTP authentication is not phishing-resistant. See phishing-resistant MFA for the methods that are.
- Shoulder surfing. A TOTP code seen over a shoulder works for one step or two. An unused HOTP code works until the server counter passes it.
- Server compromise. The verifier holds the same secret as the token, so NIST requires the verifier to protect the key with strict access controls.
Which one you meet in practice
Phone apps use TOTP. HOTP lives in tokens that have a button and no clock.
| Where | Type | Detail |
|---|---|---|
| Authenticator apps | TOTP | A new code every 30 seconds; no network needed |
| Hardware token with a button | HOTP | A YubiKey can emit an HOTP code when its button is pressed; it has no internal clock, so TOTP needs an app that reads the codes |
| SSOGEN | TOTP apps | Six digits every 30 seconds; the current code and one either side are accepted; the same code is never accepted twice. See the one-time code policy |
Questions people ask
What does TOTP authenticator mean?
A TOTP authenticator is an app or device that makes a time-based one-time password. It holds a secret key and hashes it with the current 30-second step to show a six-digit code. The service holds the same key, computes the same code and compares the two. The standard is RFC 6238.
How to know if a code is TOTP or HOTP?
A code that changes by itself every 30 seconds is TOTP; a code that changes only when you press a button is HOTP. In setup data, the key URI says which: otpauth://totp/ for time-based keys, otpauth://hotp/ for counter-based ones. An HOTP key also carries a required counter parameter.
What are the weaknesses of one-time codes?
A one-time code can be phished, because the user types it into whichever page asks. NIST SP 800-63B-4 states that OTP authentication is not phishing-resistant. The server also holds the shared secret and must protect it. HOTP tokens can fall out of counter sync; TOTP needs clocks within a step or two.
Does an HOTP code expire?
No, RFC 4226 defines no lifetime for an HOTP code. It stays valid until the server counter passes it. A successful check moves the server counter one past the matching counter, so that code and every earlier one are refused. A code pressed but never sent can still work later, inside the look-ahead window.
Sources, all read 2026-11-17: RFC 4226 (sections 7.2, 7.4, Appendix D and E.4), RFC 6238 (sections 4, 5.2, 6, Appendix B), NIST SP 800-63B-4, Google Authenticator Key URI Format, Yubico OATH overview.
Updated