TOTP Generator

TOTP code—
Seconds left—
Digits—
Time step—

How TOTP Generator is calculated: TOTP = HMAC-SHA1(secret, floor(unix time / 30)) truncated to 6 digits (RFC 6238). The code changes every 30 seconds.

What is a TOTP generator?

A TOTP generator makes the 6-digit one-time code that apps like Google Authenticator show next to your account name: the second factor you type after your password. You paste in the base32 secret that the service gave you when you turned on two-factor authentication, and the tool computes the code that is valid right now. The default secret is the well-known example JBSWY3DPEHPK3PXP, which decodes to the text Hello! plus four bytes: it is a demo secret, not a real account, and the article explains why you should never use it for a real login.

TOTP stands for time-based one-time password, and it is defined in RFC 6238. The code is not sent to you and it is not stored anywhere: both sides compute it from the same secret and the same clock, so your phone and the server agree on the code without ever talking to each other. A password generator makes the first factor, and a random OTP generator makes one-off codes for testing, but neither replaces a real authenticator app for daily use.

This tool shows the code, how many seconds it has left, the time step it came from, and that it is always 6 digits. Press the button to refresh it, and watch the seconds count down: when it hits zero, the code changes. Everything runs in your browser, and the secret never leaves your device.

The honest limit is that this page is a checker and a learning tool, not a replacement for an authenticator app. Pasting a real secret into any website, including this one, is a risk you should not take. Use your phone's authenticator for real accounts, and use this tool to understand how the codes work or to test a secret in a safe setting.

How a TOTP generator works

The recipe has four steps. First, decode the base32 secret into raw bytes: the letters A to Z and the digits 2 to 7 map to 5 bits each, and the bits are packed into bytes. Second, take the current Unix time, divide it by 30, and drop the remainder: that whole number is the time step, and it changes once every 30 seconds. Third, feed the 8-byte time step into HMAC-SHA1 keyed with the secret bytes. Fourth, take 6 digits out of the 20-byte result using dynamic truncation.

Dynamic truncation is the clever part. The last byte of the hash picks an offset between 0 and 15, and the four bytes at that offset are read as a 31-bit number, ignoring the top bit so the result is never negative. That number modulo 1,000,000 is the code, padded with leading zeroes to 6 digits. The same secret and the same time step always give the same code, on any device, in any app.

The 30-second window is a compromise. A shorter window would be safer but would fail whenever the two clocks disagree by a second or two; a longer window would be more forgiving but would give an attacker more time to use a stolen code. Most servers accept the current step and the one before and after it, so a clock that is a minute out still works. A hash generator shows the SHA-1 step on its own, if you want to see the hash function without the rest of the recipe.

The code is only 6 digits, which means a million possibilities, and that is enough because the code dies after 30 seconds and the server locks the account after a few wrong tries. Six digits are easy to type on a phone, and the short life is what makes them safe. That trade is the whole design of TOTP.

The secret and the 30-second window explained

The secret is the shared key between you and the service, and it is the only thing that must stay private. It is handed to you once, usually as a QR code, when you turn on two-factor authentication, and the service stores its copy. Anyone who has the secret can generate your codes, so treat it like a password: never share it, never screenshot it into a chat, and never paste a real one into a website you do not fully trust, including this one.

Base32 is the encoding the secret travels in. It uses only capital letters and the digits 2 to 7, so it can be read out over the phone without confusing a zero with the letter O. The example secret JBSWY3DPEHPK3PXP is the standard demo value: it decodes to the bytes for Hello! followed by four more bytes, and every authenticator tutorial uses it. It is public, so it protects nothing, and that is exactly why it is the default here.

The 30-second window is the part people notice first. The code you see has a countdown, and when it reaches zero the code changes, even if you are halfway through typing it. The seconds-left result on this page tells you how much time the current code has. If a code is about to expire, wait for the next one rather than rushing and typing it wrong.

Clock accuracy matters more than people expect. If your phone is two minutes fast, its codes will not match the server, and every login will fail with a correct-looking code. The fix is to let the phone set its time automatically. A server that accepts the neighbouring steps forgives up to a minute of drift, but no more.

A worked example: the RFC 6238 test vectors

The standard itself ships test vectors, and this tool reproduces them exactly. The test secret is the ASCII text 12345678901234567890, which in base32 is GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ. At Unix time 59, the time step is 1, the code is 287082, and it has 1 second left. At time 1111111109, the time step is 37037036, the code is 081804, again with 1 second left. Note the leading zero: the code is a string of six digits, not a number, and 081804 is not the same as 81804.

At time 1234567890, the time step is 41152263, the code is 005924, and it has the full 30 seconds left, because 1234567890 divides exactly by 30. At time 2000000000, the step is 66666666, the code is 279037, and it has 10 seconds left. These four cases are the tool's own tests, and they match the values published in RFC 6238, which is how you know the implementation is right.

Now try the page default: secret JBSWY3DPEHPK3PXP with the timestamp set to 0, which means the current time. Press the button and the code is whatever is valid in this 30-second window, with the seconds-left number counting down from 30. Press it again in a few seconds and the code is the same but the countdown is smaller; press it after the window ends and the code changes.

Type a bad secret, for example one containing the digit 1 or 0, which base32 never uses, and the tool says the secret is invalid instead of guessing. That is deliberate: a wrong secret gives a wrong code that looks right, and the only honest response is to refuse. Check the secret character by character before assuming the tool is broken.

Who uses a TOTP generator, and why

Developers testing two-factor login are the main users. When you build a login flow, you need to know what code a given secret produces at a given time, and the test vectors above are the way to check your own implementation. This tool gives you the answer in one click, with the time step shown so you can compare it against your server's clock.

Security learners are the second group. TOTP is the most widely used second factor in the world, and seeing the code change every 30 seconds, with the countdown beside it, makes the mechanism click in a way that reading the RFC does not. The worked example with the published test vectors is there for exactly that purpose.

Support staff are the third group. When a user says their authenticator code does not work, the first question is whether the code is right for the secret and the time. This tool answers that question without touching the user's account, which is the safe way to diagnose the problem. A password strength checker covers the other half of the same login, the password itself.

The tool is not for daily logins, and the article says so plainly. Your phone's authenticator app is faster, safer, and always with you, and it never asks you to paste a secret into a web page. Use this page to learn, to test, and to check, and use the app to sign in.

TOTP generator vs authenticator app

An authenticator app stores your secrets on your phone and shows all your codes at once, refreshing them every 30 seconds without you pressing anything. This page shows one code at a time for one secret, and you must press the button to refresh it. The app is built for daily use; this page is built for checking and learning.

The app also protects the secret better. It lives in the phone's storage, and it is never typed into a browser, never copied to a clipboard, and never sent over the network. Pasting a secret into any website, including this one, puts it in the browser's memory and in whatever the page does with it. This page does nothing with it except compute the code, and the code says so, but the app still has the smaller risk.

What this page has that the app does not is transparency. It shows the time step, the seconds left, and the exact algorithm, and it lets you enter a fixed timestamp to reproduce a code from the past. An app hides all of that, which is right for daily use and wrong for debugging. Use each for what it is good at.

There is no contest for real accounts: use the app. Use this page when you need to know what the code should be, when you are testing an implementation, or when you are learning how the standard works. That division is the honest one, and the page does not pretend otherwise.

Common TOTP mistakes

The first mistake is a wrong clock. If the device generating the code is more than a minute out from the server, every code fails, and the failure looks like a wrong password. Set the time automatically on every device, and check the time step this page reports against the server's clock when debugging.

The second mistake is a mistyped secret. Base32 has no digit 1 and no digit 0, and the letter O is not used either, so a secret containing any of those was copied wrong. The tool refuses invalid characters instead of guessing, which is the only safe behaviour. Copy the secret again, character by character.

The third mistake is typing a code from the previous window. The code changes every 30 seconds, and a code with 2 seconds left will be dead before you finish typing it. Wait for a fresh code when the countdown is low, and type it promptly when it appears.

The fourth mistake is sharing the secret. A screenshot of the QR code, a copy in a chat message, or a paste into a website all give someone else the power to generate your codes. Treat the secret like a password, store it in a password manager if you must store it at all, and never post it anywhere.

The fifth mistake is using the example secret for a real account. JBSWY3DPEHPK3PXP is public and appears in every tutorial, so anyone can generate its codes. It is the default here because it is safe to demonstrate with, and it must never be used to protect anything real.

How to use this TOTP generator

Paste your base32 secret into the box, leave the timestamp at 0 to use the current time, and press Generate TOTP Code. The 6-digit code appears in the box below with the seconds it has left. Type it into the login prompt before the countdown reaches zero, and if it expires, press the button again for the next code.

To check a code from the past, type a Unix timestamp instead of 0: the tool computes the code for that exact 30-second window. That is how the worked example reproduces the RFC test vectors, and it is the fastest way to check whether your own implementation agrees with the standard.

Everything runs in your browser. The secret is never uploaded, stored, or shared, and the code is computed on your device. You can use the tool offline once the page has loaded, and closing the page leaves nothing behind.

Do not paste a real secret into this page or any other website. This tool is for learning and testing with example secrets, and real accounts belong in an authenticator app on your phone. If you already pasted a real secret somewhere, turn two-factor authentication off and on again to get a fresh secret.

Frequently Asked Questions

A time-based one-time password: a 6-digit code computed from a shared secret and the current time, changing every 30 seconds. It is defined in RFC 6238 and used by Google Authenticator, Microsoft Authenticator, and most other two-factor apps. Both sides compute the same code from the same secret and clock, so no code is ever sent over the network.

Because the code is computed from the time step, which is the Unix time divided by 30. The step changes once every 30 seconds, and with it the code. The seconds-left number on this page shows how long the current code has left. If a code is about to expire, wait for the next one instead of rushing to type it.

The most common cause is a wrong clock: if the device is more than a minute out from the server, the codes never match. Set the time automatically on every device. The next most common cause is a mistyped secret, especially a 1, a 0, or the letter O, none of which base32 uses. Check both before assuming the account is broken.

No, not for a real account. The secret is the key to your codes, and anyone who has it can generate them. This page computes the code in your browser and never uploads the secret, but the safe rule is to keep real secrets in an authenticator app and use this page only with example secrets, for learning and testing.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.