HOTP vs TOTP: How One-Time Passwords Are Generated
HOTP vs TOTP is the difference between two ways of generating one-time passwords, and it explains why some codes change every thirty seconds while others wait for a button press. Both are used in two-factor authentication and both improve on SMS codes. This guide explains how each works and when to use them.
Direct answer: HOTP generates a code from a counter and a shared secret, so a new code appears each time you press a button. TOTP generates a code from the current time and a shared secret, so it changes on a fixed interval, usually thirty seconds. TOTP is more common for apps; HOTP suits hardware tokens.
What is HOTP?
HOTP stands for HMAC-based one-time password. It uses a secret key and a counter to produce a code. Each time the counter increments, a new code is generated. The server keeps the same counter, so it can verify the code without any time dependency.
The catch is drift. If the counter on the device and the server fall out of sync, codes fail. Hardware tokens and some banking devices use HOTP for this reason, since they can resync when needed.
What is TOTP?
TOTP stands for time-based one-time password. It uses a secret key and the current time to produce a code. The code changes on a fixed interval, typically thirty seconds, and the server checks the current time window to verify it.
TOTP is what most authenticator apps use. It requires the device clock to be accurate, which is why time sync problems cause codes to fail.
How the two compare
| Feature | HOTP | TOTP |
|---|---|---|
| Input | Counter | Current time |
| Code change | On button press | Every 30 seconds |
| Clock dependency | None | High |
| Common use | Hardware tokens | Authenticator apps |
| Resync | Needs counter resync | Needs time sync |
Why clock sync matters for TOTP
TOTP codes depend on the device clock matching the server clock within a small window. If your phone time is off by more than a minute, codes fail. Enable automatic date and time in your settings, especially after travel or a battery drain.
Which is more secure?
Both are secure when implemented correctly. HOTP can be vulnerable if counters drift and servers accept a wide range of values. TOTP depends on accurate clocks and proper time-window checks. Neither is inherently weak, and both are stronger than SMS codes because they do not rely on carrier delivery.
For most consumer apps, TOTP is the better user experience: no button, no counter, just a code that refreshes. For devices without a clock or with limited connectivity, HOTP is practical.
How this affects daily users
If your authenticator code fails, check your clock first. If the clock is correct and codes still fail, the secret may have been reset. Re-add the account and scan the QR code again. For apps that only offer SMS, delivery problems remain the main risk.
Developers building verification can test both flows using the OtpGet API documentation and virtual numbers for SMS fallback testing.
Frequently Asked Questions
What is the difference between HOTP and TOTP?
HOTP uses a counter that changes on each use, while TOTP uses the current time. TOTP codes refresh automatically every thirty seconds.
Which is better, HOTP or TOTP?
TOTP is more common for apps because it refreshes automatically. HOTP suits hardware tokens where a counter is easier to manage.
Why does my TOTP code fail?
The device clock is usually out of sync. Enable automatic time settings and try again.
Are OTP apps safer than SMS?
Yes, in general. Authenticator apps do not rely on carrier delivery, which removes filtering and SIM-swap risks.
Conclusion
HOTP vs TOTP comes down to counters versus clocks. Both generate secure one-time passwords, and both are stronger than SMS alone. Know which one your app uses, keep your clock synced, and use authenticator apps where possible. To test SMS fallback and verification flows, create an OtpGet account and explore the API.
Related reading: more security and OTP guides on the OtpGet blog.