Free · runs in your browser

TOTP Secret Generator

TOTP Secret Generator. Choose a secret strength and click Generate to create a random TOTP secret for 2FA setup. For recovery or QA work on an account, generate a totp code but keep the secret private since a hacker holding it can mint valid codes.

Your values

Generate a fresh secret for a new 2FA setup, or paste one you already have to check its codes.

RFC 4226 asks for at least 128 bits and recommends 160. Every authenticator app accepts 20 bytes.

Bulk generation: one secret per user. Only the first one is used for the URI and codes below.

Google Authenticator and most apps only use SHA-1. Change it only if your server is set to SHA-256 or SHA-512.

Usually 6.

How long each code lasts. Usually 30 seconds; some tokens use 60.

How many periods before and after now to list in the code table, to check for clock skew.

Shown as the account's name in the authenticator app.

Builds a Microsoft Entra ID hardware-token import row for this secret.

Result

TOTP Secret (Base32)
—
Hex Seed
—
OTPAuth URI (for QR Codes)
—
Current One-Time Password
—
Code Updates In
—
Estimated Entropy
—
Strength
—
Average Time to Guess at 1 Million Guesses per Second
—
Average Time to Guess at 1 Trillion Guesses per Second
—
Secret Length
—
All Generated Secrets (copy)
—
Entra ID Import CSV
—
  • No account, no logging
  • Open formulas explained below
  • Works offline once loaded

Building a login that asks for a second factor? A TOTP secret generator gives you the random key that your server and a user's authenticator share, so each side can compute the same one-time password without ever talking to the other. Below you create that value in four steps, see how it turns into a six-character code, and load it into Google Authenticator or any other 2FA authentication app that you trust with a password-grade secret.

TOTP Secret Generator: Create Your Own in Four Steps

Every base32 secret begins as random bytes, so the quickest route is a free browser page that runs locally. Any TOTP secret key generator follows the same flow, and you should verify the result before you ship the setup to real users. For authenticator app enrollment, the otpauth uri builder assembles a key URI with secret, issuer, account label, algorithm, digits and period as query parameters.

Bar chart of entropy in bits and Base32 length for 10, 16, 20 and 32 byte TOTP secrets, with the 20-byte secret highlighted
Entropy and Base32 length by secret size.
  1. Open the generator and choose 20 random bytes.
  2. Copy the 32-character string it shows.
  3. Paste that string into your authenticator or your server.
  4. Type the first code that appears, then confirm both sides match.

Typical uses for a freshly generated value:

  • Seeding test users in a staging environment
  • Enrolling a hardware fob or a spare phone
  • Documenting a recovery path for your team

Copy the Setup Key

Your setup key is the same value some services print beside their QR image as a secret key. Treat those 32 characters like a password: copy them once and never paste them into a chat window.

Paste It into a 2FA Generator and Match Options

Paste the string into a 2FA generator, then choose the algorithm, length and period your service expects. A tool with one mismatched option still produces plausible numbers that your server rejects.

How a Setup Key Becomes a 6-Digit TOTP Code

A time-based one-time password is an HMAC over a counter that moves every 30-second step. Your TOTP generator divides the Unix timestamp by 30, signs that counter with the decoded bytes, and keeps the last six digits of the result. The one-time token is therefore a pure function of the secret and the clock.

Heatmap of random-guess odds for 6 and 8 digit TOTP codes across verification window sizes
Guess odds by digit length and verification window.

$$C = \left\lfloor \frac{T}{30} \right\rfloor \qquad \text{OTP} = \text{Trunc}\big(H_K(C)\big) \bmod 10^{6}$$

Here is a run I computed for a fresh secret. The verification code your server expects at that instant is 322645.

How a Setup Key Becomes a 6-Digit TOTP Code
Generator stepValue
Secret (Base32 encoding)UVG4UGBFGC5R23ITFTPNMI33F3MR4P3S
Timestamp T (seconds)1793700000
Counter C59,790,000
Digest begins007f8e06bd15
Offset (last nibble)2
31-bit number235,322,645
6-digit result322645

Move the timestamp forward by 30 seconds and the counter becomes 59,790,001, which produces an entirely different six-digit result, because changing one input bit scrambles the whole digest. That avalanche effect is why an old value is useless to an eavesdropper a minute later.

Time Period and Digit Count

The default time period is 30 seconds and the default length is six digit places, though some services use eight. Both sides must agree, otherwise the algorithm output diverges. Servers commonly accept one step on either side of the current one to absorb small clock drift, so a value stays acceptable for roughly 90 seconds in total.

HMAC-SHA1 and the RFC 6238 Standard

RFC 6238 defines the method, and HMAC-SHA1 is its default hash. SHA-256 variants exist, but many apps ignore them.

Base32 Secret Length and Strength

A good secret key generator draws random bytes from a secure source, then applies RFC 4648 encoding so you can type the value by hand. Skip hand-made values such as dictionary words or birthdays: they shrink the search space dramatically even when padded out to 32 characters. Twenty bytes appear as 40 hex characters or 32 Base32 characters.

Entropy and Random Bytes

Twenty random bytes carry 160 bits of entropy, about 1.46 × 1048 possible values, which is far beyond any guessing attack, even for an attacker with a large cluster running for years.

Enrolling a Staging User with a TOTP Secret Key Generator

Priya, a QA engineer, needs a repeatable second-factor login for a staging site before Friday's release. She opens a TOTP secret generator, picks 20 bytes, and gets CQI2BIYXX2G63S7JUEOPOXQELVSRA2YH. She pastes it into the staging admin form, then into her authenticator app with the default 30-second period and six digits.

Timeline of one 30-second TOTP time step with the previous and next steps a server still accepts
One 30-second step and its verification window.

At Unix time 1793712345 the counter is 59,790,411 and the app shows 444186. The server accepts it. She cross-checks by computing the same HMAC-SHA1 value in Python, then confirms the neighbouring steps too:

Enrolling a Staging User with a TOTP Secret Key Generator
StepCounterValue
Previous59,790,410091732
Current59,790,411444186
Next59,790,412482037

Her staging server accepts one step either side, so three values derived from that one secret are valid at once. What stands out is the guessing math: one try now has a 3-in-1,000,000 chance, not 1-in-1,000,000. Against a lockout threshold of five failed attempts, an attacker's odds per cycle are 15 in 1,000,000, or 0.0015%. That is acceptable for staging, and the number she watches is the lockout threshold, not the window. If the site were public-facing she would shrink the window to the current step only, so the 160-bit secret's six-digit output stays hard to guess, trading a few rejected logins from slow phones for a third of the guessing odds, and she would also alert on repeated failures from one address.

An edge case trips her team next: they switch a test client to eight digits and see 64444186. The last six digits are still 444186, because both lengths truncate the same 31-bit number. A service expecting six digits would reject the longer entry, so she records the period and length beside the key in the team's password manager and enables rate limiting before release. Her rule of thumb: record every parameter at creation time, because a secret without its period, length and hash is hard to reuse later.

2FA TOTP Generator QR Code and OTPAuth URI

Most services want an OTPAuth URI so they can draw a QR code. The URI packs the secret together with an issuer and an account label, for example otpauth://totp/Acme:[email protected]?secret=UVG4UGBFGC5R23ITFTPNMI33F3MR4P3S&issuer=Acme. You scan the image once and the app stores everything. Never paste the image into a ticket or a screenshot, because it is the credential itself.

Google Authenticator QR Code Import

Open Google Authenticator, choose the scan option and point the camera at the image. Advanced options are ignored there, so only the secret, issuer and account carry over.

TOTP Code Generator Examples in Python, Node.js and OpenSSL

Developers usually wire the implementation into a server through a library. In Python, pyotp needs one line, and in Node.js the otplib package works the same way. An API endpoint can wrap either one. Whatever you pick, compare values in constant time and reject one that was already used in the same window, which blocks replay.

pyotp.TOTP("UVG4UGBFGC5R23ITFTPNMI33F3MR4P3S").now()

Bulk Generation from the Terminal

For bulk generation, the terminal and OpenSSL do the job: openssl rand -hex 20 prints 40 hex characters per run, so a short loop yields as many values as you need.

Protect Your Authenticator Secret from Phishing

Anyone holding the secret can mint valid codes, so treat it as sensitive data and keep it private. Choose a tool that runs locally: a client-side page that works offline, so the value is never uploaded. A phished value is as damaging as a stolen password.

Backup Codes and a Password Manager

Store backup codes and the secret in a password manager, never in screenshots. If you lose your phone, those codes are your way back into the account.

2FA Generator Troubleshooting for Mismatched Codes

If a code is rejected, check the device clock first, because a drift past 30 seconds breaks every value. Next confirm the authenticator app uses the same secret, algorithm and period. Apps such as Authy and Microsoft Authenticator accept the same Base32 input, and a Microsoft account shows its own setup page. For a TOTP secret that still fails, regenerate it and repeat the four steps. Finally, make sure the length matches: a service that expects eight characters will never accept a six-character entry.

Frequently Asked Questions

What is a TOTP secret?
A TOTP secret (also called a seed or shared key) is the random value an authenticator app and a service both store to generate matching time-based one-time codes. It's usually shown as a Base32 string (letters A-Z and digits 2-7) because that alphabet is easy to type and scan from a QR code without ambiguous characters.
How long should my TOTP secret be?
RFC 4226 (the HOTP specification TOTP builds on) recommends at least 128 bits, and specifically suggests 160 bits for HMAC-SHA1-based implementations. This tool defaults to 160-bit (32 Base32 characters), which matches what most services and authenticator apps generate. 80-bit (16 characters) is shorter and easier to type manually, but offers a smaller margin of safety.
Is this secret compatible with Google Authenticator, Authy, and other apps?
Yes. The Base32 output is the standard format every major authenticator app (Google Authenticator, Authy, Microsoft Authenticator, 1Password, Bitwarden) expects, either typed in manually or embedded in an otpauth:// QR code. Use the OTPAuth URI Builder or Two-Factor QR Code Generator to turn this secret into a scannable enrollment code.
Does the secret get sent anywhere?
No. This tool generates the secret entirely in your browser using the Web Crypto API's cryptographically secure random number generator. Nothing is transmitted, logged, or stored — reload the page and the secret is gone.
Can I use this secret for both TOTP and HOTP?
Yes — the secret itself is just random key material; whether it's used with a time counter (TOTP) or an event counter (HOTP) is decided when you build the otpauth:// URI or configure the service, not by anything encoded in the secret.

About the author

Vinitha Pu

Founder and designer

Vinitha Pu is a graphic designer based in Palakkad, Kerala, who builds free, privacy-friendly browser tools. She studied Textile and Apparel Design at Avinashilingam University and completed a C-Tech in Graphic Design at Image Creative Education in 2025. She designs, builds and maintains the password generators, strength checkers, hash tools and security calculators on PasswordHive.

  • Content author: Vinitha Pu
  • Fact checked by: Vinitha Pu. Each tool's output is checked against official test vectors or a reference implementation, and every strength and crack-time figure against the formula it uses, before it goes live.
  • Published Updated