Need a string nobody can guess? Our random token generator creates secure tokens and API keys in your browser, so you can pick a size, copy the result and get back to your workflow. This guide explains how the values are built, how many bits of entropy you actually need, and how to protect every API credential once it leaves the page.
How a Token Generator Creates Random Tokens
A token is an opaque string that identifies or authorizes a user, a device or a session. The only property that matters is that attackers cannot predict it. A good generator therefore does one job: it turns unpredictable bytes from a cryptographically secure source into text you can paste into a config file, an HTTP header or a database row. Security here is a property of the source, not of how clever the string looks. That is why secure random tokens start with entropy, never with a pattern, and why a cryptographically secure source is the first thing to check in any tool, since cryptographically secure randomness is what makes the final value hard to guess. Need to generate a rails secret key base? There is a free, no-sign-up tool for exactly that.
Where the Randomness Comes From
Every value comes from the Web Crypto API, specifically crypto.getRandomValues(). That call is a secure random number generator built into your browser and seeded by the entropy pool of your operating system, the same CSPRNG that protects TLS sessions. Server-side languages expose the equivalent as random bytes, for example openssl rand in a terminal or the secrets module in Python. Whichever algorithm sits underneath, the contract is the same: observing output reveals nothing about the next value.
Why Math.random() Is Not Enough
Math.random() is a pseudorandom generator. Its output is predictable once someone observes a few values, so it must never produce anything sensitive. It is fine for shuffling a playlist; it is wrong for a credential. If an online tool still builds your keys that way, close the tab.
Random Token Generator Settings: Bit Length, Encoding and Prefix
The generator exposes three choices. Each one changes the output in a different way, so it helps to know what you are trading. The aes encryption key generator runs entirely client-side — nothing you enter or generate is ever stored or transmitted.
Bit Length
The bit length sets how many random bits go into the value before encoding. Common choices are 64-bit for throwaway identifiers, 128-bit as the floor for anything guarding access, 256-bit for long-lived credentials, and 512-bit, 1024-bit and 2048-bit only when a compliance rule demands it. Low-security stubs and high-security tokens differ mostly in this one number.
Encoding: Hex, Base64 and Base64URL
Encoding changes how the same random bytes look on screen, not how strong they are. Hex (hexadecimal) stores 4 bits per character, Base64 stores 6, and Base64URL swaps the two awkward characters so the string is URL-safe. A numeric PIN suits short one-time codes. Pick whatever your destination accepts, whether that is a header for API tokens or a config field for keys, and your alphanumeric or hex choice will not change the strength; the bytes are encoded differently but carry identical strength.
Prefix and Character Set
A prefix such as sk_live_ or tok_ is plain text added in front of the random part. It adds no entropy, but it labels the string. The character set you choose (uppercase, lowercase, digits, alphanumeric only, or extra special characters) sets how many possibilities each position holds, which feeds straight into the formula below.
Token Length and Entropy: The Formula Behind Secure Tokens
Strength is counted in bits, and the arithmetic is short. For a token of L characters drawn uniformly from an alphabet of N symbols:
$$\text{entropy (bits)} = L \times \log_2 N$$
To go the other way and find the token length you need for a target strength B:
$$L = \left\lceil \frac{B}{\log_2 N} \right\rceil$$
Hex has N = 16 (4 bits per character), Base32 has 32 (5 bits), a 62-symbol set of letters and digits gives about 5.95 bits, and Base64 gives 6 bits per character.
Worked Example: A 192-Bit Token
Suppose you want a unique identifier for a webhook and decide on 192 bits. In hex you need 192 ÷ 4 = 48 characters. In Base64URL you need 192 ÷ 6 = 32 characters. With a 62-symbol set you need \(\lceil 192 / 5.954 \rceil = \)33 characters. All three are equally hard to guess, because each holds 2192 ≈ 6.28 × 1057 possible values; only the text length differs.
| Bit length | Hex characters | Base32 characters | Letters and digits | Base64URL characters |
|---|---|---|---|---|
| 64 | 16 | 13 | 11 | 11 |
| 128 | 32 | 26 | 22 | 22 |
| 192 | 48 | 39 | 33 | 32 |
| 256 | 64 | 52 | 43 | 43 |
| 384 | 96 | 77 | 65 | 64 |
How Long Should Random Tokens Be?
128 bits of entropy is the floor for anything protecting access, and it is the strength NIST SP 800-63B expects from a randomly generated value. Past 256 bits you gain nothing against a brute-force attack; you only pay in log volume and header size.
The table assumes an attacker making one trillion attempts per second and, on average, searching half the space. A brute force run against a 64-bit value is within reach, while 128 bits is not.
| Bits of entropy | Possible values | Average time to crack |
|---|---|---|
| 56 | 7.2 × 1016 | about 10 hours |
| 64 | 1.8 × 1019 | about 0.29 years |
| 80 | 1.2 × 1024 | about 19,000 years |
| 128 | 3.4 × 1038 | about 5.4 × 1018 years |
| 192 | 6.3 × 1057 | about 9.9 × 1037 years |
Hitting one value is only half the story. If you issue millions of tokens, you also care about a collision, two users receiving the same string. The birthday bound says a 128-bit space reaches a 50% collision chance after roughly 2.2 × 1019 tokens, far beyond any real system.
Token Types: Bearer Token, Access Token and Session Tokens
These token types describe how a credential is used, not how it is generated. At creation time all of them are the same thing, a high-entropy random string.
- A bearer token grants access simply by being presented, which is why the authorization header carries it verbatim over HTTPS.
- An access token is a bearer credential with a short lifetime, usually issued by an OAuth flow for authorization decisions; access tokens and bearer tokens are generated identically.
- Session tokens keep a signed-in visitor recognised between requests; a session ID is the classic case.
- Long-lived API credentials belong to a service rather than a person, while a password-reset link or a one-time PIN sits at the short end of the scale.
A JWT is different: it is a structured, signed document, so you generate its signing key here but not the JWT itself. A UUID v4 is a random value with a fixed 36-character shape and 122 random bits; use it when a database column expects a UUID, and plain hex when the format is yours to choose.
Token Generator Walkthrough: An API Key for a Nightly Billing Export
Marguerite maintains a small billing service, and a partner's nightly export job needs its own API key to pull invoices. Her old key was a 12-character string a colleague typed by hand, and it has been sitting in a shared spreadsheet for two years. She wants a replacement she can defend in the next vendor review.
She opens the generator and sets 160 bits, because the export runs unattended for months and she wants headroom over the 128-bit minimum that NIST SP 800-63B expects of a random secret. She picks Base64URL so the value survives being pasted into a query string, types the prefix bex_ for "billing export", and clicks generate.
The result is 27 characters, since 160 ÷ 6 = 26.67 rounds up to 27, which carries 162 bits in total. Her check against the formula is quick: at one trillion attempts per second, searching half of a 162-bit space takes about 9.2e28 years. The old hand-typed string, at roughly 12 × 5 = 60 bits, would fall in about two months by the same arithmetic.
- Value:
bex_followed by 27 random Base64URL characters - Strength: 162 bits against a 128-bit floor
- Next action: store it in the secrets manager, never in the spreadsheet
The figure settles one decision and opens another. Because 162 bits clears the floor with room to spare, she does not rerun with a longer length. Instead she sets a 90-day expiry on the partner's side, adds the bex_ prefix to the secret scanner's pattern list, and revokes the old key once the first export succeeds with the new one.
API Token Generator and API Key Generator Use
Used as an API token generator, the tool produces API tokens, strings that a client presents on every request. Used as an API key generator, it adds one extra step: a prefix. GitHub, Stripe and Slack all prefix their API keys so that secret scanners can recognise a leaked credential from the string alone. When a prefixed key lands in a public repository, the issuer can revoke it within minutes. A bare 32-character hex string looks like a commit hash, so nothing catches it.
Prefixes also separate environments at a glance. A stg_ key in a production config is an obvious mistake; an unmarked one is not.
Token Generation for Web Applications: Authentication and Access Control
Most web applications need random strings at three points. First, authentication: after a login, the server issues a session value and checks it on every request. Second, access control: API tokens prove a caller may reach a given route, and scoping each one narrowly limits what a stolen copy can do. Treat API tokens as per-client keys, issue separate API keys per service, and keep a list of which keys exist, since API security depends on knowing what you handed out. Third, integration with third parties, where a webhook signing value proves a message really came from the sender.
For developers, the typical workflow is short: generate a value here, store it in a vault, reference it from your deployment, and let the application verify it on each call. Good authentication design never relies on the token alone; pair it with HTTPS, expiry and logging of failed attempts.
How to Use the Random Token Generator
- Choose the bit length that matches your threat model; 128 is the safe default and 256 suits long-lived API tokens and API keys.
- Select an encoding: hex for simplicity or a compact URL-safe encoding.
- Add an optional prefix and set how many values you need; bulk generation returns a whole batch at once.
- Click generate, then use one-click copy. Each value is unique and unguessable by design.
Storing and Rotating Generated API Tokens in Production
Once the generator hands you a value, the easy half is done. The weak points are where that API token goes next. Follow these habits so a good token stays good:
- Store securely in a secrets manager for production keys and a password manager for personal logins.
- Pass values through environment variables, and never commit them to version control.
- Keep tokens encrypted at rest with encryption such as AES-256 (disk or database encryption), and store only a SHA256 hash of each token you generate if you only need to verify it later. MD5 is a legacy choice and not recommended.
- Add an expiration and rotate on a schedule; token rotation limits the damage from an unnoticed leak.
- Keep tokens out of logs; redact or hash them first, and apply the same security care to every API key you issue, because keys leak most often through logs and screenshots.
Testing With Generated Tokens: Staging and Sandbox
Developers also use this tool for testing. Creating dummy tokens lets you exercise authentication flows in a sandbox or staging environment without touching real credentials, and mocking a session ID takes seconds. Automated testing benefits too: a fresh value per test run avoids stale fixtures. Keep one rule: a value pasted into a test fixture is no longer private, so never reuse it in production.
Client-Side Generation and Privacy
Everything on this page is client-side: values are produced in your browser, and nothing is sent to a server. Open your network tab, generate a token and watch for traffic; there is none. That matters for privacy and for overall security, because a string that has crossed a network may sit in someone else's request log. For cryptographic key material such as AES or RSA, prefer vetted libraries or OpenSSL, since the rules for those are stricter than for tokens. If you need human-friendly passwords instead, use a dedicated password generator rather than a token.
Common API Token Generation Mistakes
Most incidents trace back to a few choices made at generation time: a too-short token because it was easier to read, one generated token reused across environments, no label so a leak cannot be recognised, and a value left exposed after a compromise. Treat a generated token like a password: unique per purpose, stored once, rotated on schedule, and revoked the moment you suspect exposure. Careful settings remove the guesswork, but the surrounding habits decide whether your API security holds, and one careless paste into chat can undo a 256-bit choice.
Frequently Asked Questions
- What's the difference between the formats?
- They're all encodings of the same random bytes, not different levels of randomness. Hex uses 2 characters per byte and only 0-9a-f (safest for shells and config files); Base64 packs 3 bytes into 4 characters using 64 symbols including + and /; Base64URL is the same but URL-safe (- and _ instead); Alphanumeric skips byte-encoding entirely and draws directly from a 62-character letters+digits set, useful when symbols like +, /, or = would break a system that only expects word characters.
- How many bytes should I use?
- 32 bytes (256 bits) is a strong general-purpose default for session tokens, API keys, and CSRF tokens. Use 16 bytes (128 bits) for shorter-lived, lower-stakes tokens where length matters for usability; go up to 64 bytes for long-term secrets you want an extra security margin on.
- Is alphanumeric output as secure as hex or Base64 at the same byte length?
- Not quite in raw bit terms, since it draws each character independently from a 62-symbol alphabet rather than encoding true random bytes, but the practical difference is negligible at normal lengths -- a 32-character alphanumeric token still has roughly 190 bits of entropy (32 × log2(62)), far beyond what's needed for any realistic token use case.
- Can I use this for API keys, session tokens, and CSRF tokens?
- Yes -- this is exactly the kind of general-purpose random value those all need: a cryptographically unpredictable string with no exploitable pattern. Choose the format that matches where you're pasting it (URL-safe for query parameters, hex for config files, etc.).
- Is this token sent anywhere when generated?
- No. It's generated entirely in your browser using the Web Crypto API's cryptographically secure random number generator -- nothing is transmitted, logged, or stored.