TOTP Generator
Generate TOTP codes (RFC 6238) from a Base32 secret. Supports SHA-1/256/512, 6-8 digits and custom periods, entirely offline.
- Secret never leaves your browser
- Nothing you paste is uploaded
- Works instantly, no signup
Last updated: Oct 23, 2026 14:03:06
Generate a one-time code
Computed in your browser: the secret is not uploaded and not stored. The page makes one analytics request and nothing else.
A TOTP generator produces the six-digit code that authenticator apps show, using the algorithm in RFC 6238. Given the same secret and the same clock, this page and your phone will show the same digits at the same moment — no server, no sync, no account.
This is useful for three kinds of people: someone who lost access to the app but kept the secret, someone who needs to verify that a service and their phone really agree, and developers who need to check an implementation. Below: how the algorithm works, which parameters change the output, and why clock drift is the single most common reason a valid-looking code is rejected.
How TOTP works, step by step
Five steps, all of them cheap:
- Divide time into steps. Take the current Unix time in seconds and divide by the period (30 by default). The integer result is the counter. At Unix time 1,700,000,000 the counter is 56,666,666; thirty seconds later it is 56,666,667.
- Encode the counter. The counter is written as a big-endian 64-bit integer — exactly eight bytes.
- HMAC it. Compute HMAC over those eight bytes, keyed with your secret and using the chosen hash (SHA-1 by default). Output is 20 bytes for SHA-1, 32 for SHA-256, 64 for SHA-512.
- Truncate. Look at the low nibble of the last byte; treat it as an offset. Read four bytes starting there, drop the top bit, and you have a 31-bit integer.
- Modulo. Divide by 10digits and keep the remainder, then zero-pad. Six digits means modulo 1,000,000.
Nothing in that chain is secret except the key, and nothing depends on the server beyond the clock. That is why a code can be generated offline on a laptop, a phone, or a page like this one.
A useful sanity check: TOTP is HOTP with the counter derived from time instead of incremented by hand. If you understand HOTP, you already understand TOTP — the only new input is the clock. If you do not care which variant you are looking at and just need a code, the OTP generator is the general entry point; this page is the one that exposes every parameter.
The secret: Base32, and why it looks like that
Secrets are shared as Base32 because the format survives being read aloud, typed on a phone, or printed on a sticker. Base32 uses A–Z and 2–7 only: no lowercase ambiguity, no 0 versus O, no 1 versus l.
What that means in practice:
- Case does not matter.
jbswy3dpehpk3pxpandJBSWY3DPEHPK3PXPare the same key. - Spaces and dashes are formatting. Services often print
JBSW Y3DP EHPK 3PXPfor legibility. Strip the spaces and it works here. - Padding is optional. Trailing
=signs are ignored by most implementations, including this one. - Any other character is a fatal error. A
1,0or8in the key means it was copied from a QR decode that substituted characters, or that you are looking at the wrong string.
A key that decodes to fewer than 10 bytes should be treated with suspicion — RFC 4226 requires at least 128 bits (16 bytes), and most services issue 20 bytes (32 Base32 characters).
The four parameters
| Parameter | Common value | Effect on the output |
|---|---|---|
| Hash algorithm | SHA-1 (older SHA-256, SHA-512 for enterprise) | Changes the HMAC digest, so every digit changes. Google Authenticator itself only supports SHA-1; many enterprise IdPs offer SHA-256. |
| Digits | 6 (7 for some banks, 8 for some enterprise) | Changes the modulus. A 6-digit code read as 8 digits will be rejected even though the underlying integer is correct. |
| Period | 30 seconds (60 and 90 exist) | Changes the counter, so the code is out of phase with the server’s expectation. |
| Secret | Base32, 16–32 bytes | The key itself. This is the only value that must be exact. |
All four are encoded in an otpauth://totp/ link when a service shows a QR code. Pasting that link into the field above sets them automatically, which removes the guesswork.
Clock drift: the number one cause of rejected codes
The server computes the expected code from its clock. Your device computes it from yours. If the two disagree by more than one time step, the codes can never match — and no amount of retyping helps.
How much tolerance exists depends on the service. Many accept the previous and next step (roughly ±30 seconds); stricter ones accept only the current step. That means a device that is 40 seconds fast will look “almost right” and fail consistently, which is the most frustrating failure mode there is.
Two things worth knowing:
- Time zone is irrelevant. TOTP uses Unix time (UTC seconds since 1970). Changing your phone from Shanghai to London does not shift the counter — only the clock’s absolute accuracy matters.
- Checking is easy. Open a site that shows the current Unix time, compare with your device’s seconds. A difference above 10 seconds is worth fixing; above 30 is almost certainly your problem.
Fix by enabling automatic time synchronisation (NTP) on the device, then reopening the app. On phones this is usually under Settings → Date & time → “Set automatically”.
Will this match my app?
If the secret, algorithm, digits and period match, the digits match. That is true for every standard implementation — the compatibility caveats, including the cases where an app silently disagrees, are covered in the authenticator compatibility notes:
- Google Authenticator — SHA-1, 6 digits, 30 seconds.
- Microsoft Authenticator — SHA-1, 6 digits, 30 seconds for TOTP entries.
- Authy, 1Password, Bitwarden, Aegis, 2FAS — same standard; some support SHA-256 and 8 digits when the service asks for it.
- Hardware tokens — often HOTP rather than TOTP, and some use proprietary schemes that are not compatible at all.
A quick verification trick: generate a code here and in your app within the same 30-second window. If the first four digits match and the last two differ, you are almost certainly one step apart — a timing problem, not a wrong secret.
A worked example you can follow
Take the secret JBSWY3DPEHPK3PXP (the well-known test value), SHA-1, 6 digits, 30 seconds. At Unix time 1,700,000,000:
- The counter is
1700000000 ÷ 30 = 56,666,666(integer division). - That counter becomes eight bytes:
00 00 00 00 03 60 AA 2A. - HMAC-SHA-1 of those bytes, keyed with the decoded secret, gives 20 bytes.
- The last byte’s low nibble picks the offset; four bytes from there, top bit cleared, produce a 31-bit integer.
- That integer modulo 1,000,000, zero-padded to six digits, is the code.
Change any single input — one byte of the secret, the hash, the digit count, the period — and the output changes completely. That sensitivity is a feature: a mistyped key does not produce a “close” code, it produces an unrelated one.
Why six digits is enough
Six digits give one million possibilities. An attacker guessing blindly has a one-in-a-million chance per attempt, and services throttle or lock after a handful of wrong codes. Combined with a password that must also be correct, that is far beyond practical online guessing.
It is not beyond offline guessing of the secret, though. If an attacker obtains the secret itself, no digit count saves you — which is why the secret deserves better protection than the code ever does.
If you are implementing this yourself
The whole algorithm fits in about thirty lines. The pitfalls are all in the details:
- Counter encoding. Eight bytes, big-endian, unsigned. A 32-bit counter breaks in 2038; a signed integer breaks on large values.
- Truncation. Offset comes from the low nibble of the last byte, and the top bit of the first selected byte must be masked off.
- Padding.
42must render as000042. Half of all first implementations fail here. - Time source. Floor the seconds; do not round. A counter that occasionally rounds up produces intermittent failures that are painful to debug.
Test against the RFC 4226 vectors before trusting your output: with the secret 12345678901234567890, the first HOTP values are 755224, 287082, 359152. If those match, your HMAC, truncation and padding are correct.
“But my app shows a different code”
Three explanations, in order of likelihood:
- You are looking at a different account. One service, two entries (work and personal), same issuer name. Check the label, not just the digits.
- The parameters differ. The service may have issued an 8-digit or SHA-256 entry while your app defaults to 6/SHA-1.
- The code rotated between reads. You looked here at second 29 and there at second 31. Compare within the same step, or watch both for a full cycle.
Security notes
A generator page is only as trustworthy as its ability to not keep your secret. This page is deliberately limited:
- Nothing you paste is sent anywhere: the only outgoing request the page makes is its own page-view counter.
- Nothing is stored — no cookie, no localStorage, no session record.
- The secret lives in one input field and is discarded when the tab closes.
That still leaves risks outside the page’s control: a browser extension with page access, a shared computer, or someone reading over your shoulder. If you plan to keep using this long term, save the secret in a password manager rather than in a note, and read 2FA backup codes so a lost phone is a nuisance instead of an emergency.
When a code is rejected despite correct parameters, go through the troubleshooting checklist. For the underlying definitions, see what TOTP is and the HOTP generator for the counter-based variant.
Frequently asked questions
Why does my code not match my authenticator app?
Three causes, in order: a different account entry, different parameters (digits, algorithm or period), or the code rotating between the two readings. Compare both within the same 30-second window.
Does the time zone affect TOTP?
No. TOTP counts UTC seconds, so changing the time zone does not shift the counter. Only the absolute accuracy of the clock matters.
What period should I use?
30 seconds unless the service says otherwise. 60-second windows exist on some older systems, and using 30 there makes the code valid only half the time.
Which algorithm does TOTP use by default?
SHA-1. SHA-256 and SHA-512 are optional and mostly seen in enterprise identity providers; they change every digit of the output.
Why does my app only show 6 digits when the site asks for 8?
The service issued an 8-digit entry and the app is falling back to defaults. Re-scan the setup link, or paste it into this generator to see the parameters it carries.
Can I use TOTP without internet access?
Yes. The code depends only on the shared secret and the clock, so it works fully offline.