TOTP Code Generator

Generate a Time-based One-Time Password (RFC 6238) — SHA-1, SHA-256 or SHA-512.

Open tool

Overview

The TOTP code generator produces the same 6 or 8-digit codes that Google Authenticator, Authy, Microsoft Authenticator, and every other software MFA app produce. Paste a Base32 secret, optionally adjust algorithm and period, and the tool shows the current code along with a countdown to the next refresh.

It is built for engineers debugging "why is my TOTP code rejected" against a backend implementation, sysadmins recovering a code from a backed-up secret without scanning the QR again, and security researchers cross-checking RFC 6238 test vectors. A TOTP code generator with the option to pick SHA-256 or SHA-512 also helps when working with non-default IdP setups.

How it works

TOTP (Time-based One-Time Password, RFC 6238) is HOTP (RFC 4226) with a time-derived counter. The counter is T = floor((current_unix_time - T0) / period), where T0 is typically 0 and period is typically 30 seconds. The code is:

HMAC = HMAC-<alg>(secret, T as 8-byte big-endian)
offset = HMAC[19] & 0x0F
chunk = HMAC[offset..offset+4] interpreted as big-endian 32-bit int, top bit masked off
code = chunk mod 10^digits

The default algorithm is SHA-1, with SHA-256 and SHA-512 as optional alternatives — though many authenticator apps still only support SHA-1. Codes are typically zero-padded to 6 digits; 8 digits is the alternate form used by some YubiKeys and government systems. The 30-second window is what causes the familiar "you have 12 seconds to type this" pressure during login.

Examples

Secret:    JBSWY3DPEHPK3PXP   (base32)
Algorithm: SHA-1
Period:    30s
Digits:    6
Time:      now
Output:    123456 (refreshes every 30 s)
Secret:    GEZDGNBVGY3TQOJQ
Algorithm: SHA-256
Digits:    8
Output:    12345678
RFC 6238 Test Vector:
Secret (ASCII): 12345678901234567890
Time:           59
Output:         94287082 (SHA-1, 8 digits)

FAQ

Why does the secret have to be Base32?

RFC 6238 specifies Base32 (RFC 4648) for the secret encoding because it is case-insensitive and avoids characters that look alike in handwriting. Hex and Base64 secrets need to be re-encoded to Base32 before pasting into most authenticator apps.

Why is SHA-1 still the default?

Compatibility. The original spec is built on HMAC-SHA-1 and most authenticator apps default to it. The cryptographic weakness of SHA-1 (collision attacks) is not relevant here — TOTP needs preimage resistance of HMAC, which SHA-1 still provides.

My code is off by one period — clock skew?

Yes. TOTP tolerates a ±1 period drift on the server side (±30 s by default). Anything beyond that needs a system clock adjustment on the device generating the code.

Are TOTP secrets shared with the server?

Yes — TOTP is a symmetric secret, known to both client and server. That is its primary weakness compared with FIDO2/WebAuthn, where the server holds only a public key.

Try TOTP Code Generator

An unhandled error has occurred. Reload ×