Free tool · Developer tools
Random token generator
In this random token generator you pick how many bytes of randomness you want and how they are written, and the tokens appear at once. The starting choice is 32 bytes in base64url, which gives 43 characters and 256 bits, and the page shows how many tokens you could issue before a repeat becomes likely.
- Free
- No sign-up
- Runs in your browser
- 5 tokens, all different
- Randomness per token
- 32 bytes, 256 bits
- Characters per token
- 43
- Alphabet
- 64 symbols, 6 bits each
- Repeat chance across 1 million tokens
- 1 in 2.3 x 10^65
- Tokens before a 1 in a billion repeat
- 1.5 x 10^34
How to use the Random Token Generator
- Set Bytes of randomness. Each byte adds 8 bits, so 16 bytes is 128 bits and 32 bytes is 256 bits.
- Choose how the bytes are written under Write the bytes as: hex, base64, base64url or base32.
- Add a Prefix if your tokens carry a label such as key_, and set How many tokens you need.
- Read the detail lines under the list, then press Copy all. Generate again draws a new set.
How do I generate a random token?
A token is a run of random bytes written in a text alphabet. The page asks your browser for the bytes with crypto.getRandomValues, the generator meant for secrets, and then converts them. Take the 16 bytes 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff. In hex they read 00112233445566778899aabbccddeeff. In base64url they become the 22 characters ABEiM0RVZneImaq7zN3u_w, in padded base64 ABEiM0RVZneImaq7zN3u/w==, and in base32 AAISEM2EKVTHPCEZVK54ZXPO74. The bytes are the same in all four, only the spelling changes.
The prefix is plain text placed in front of the encoded part, for example key_ followed by the token. It helps people tell token types apart in logs and adds no randomness. All tokens in one batch are different, and nothing is stored or sent anywhere.
How long should a random token be?
Length decides how likely two tokens are to collide and how hard one is to guess. A token with b random bits has 2 to the power b possible values. Guessing one correctly takes on average half of them, and two tokens drawn at random clash after about the square root of that number, a rule known as the birthday bound. The last column of the table is that point for a 1 in a billion chance of a repeat, worked out as the square root of 2 times 2 to the power b times 1e-9.
The table shows why 64 bits suit a short lived code and why 128 bits suit an identifier that must never clash: at 8.2 x 10^14 tokens issued, a repeat is still a 1 in a billion event. A million tokens of 128 bits give a repeat chance of 1 in 6.8 x 10^26, and a million tokens of 64 bits give 1 in 3.7 x 10^7. For anything that protects data, choose the length your own security requirements name. These figures are plain arithmetic, not advice.
| Bytes | Bits | Hex chars | Base64url chars | Base32 chars | Tokens before repeat |
|---|---|---|---|---|---|
| 8 | 64 | 16 | 11 | 13 | 190,000 |
| 16 | 128 | 32 | 22 | 26 | 8.2 x 10^14 |
| 24 | 192 | 48 | 32 | 39 | 3.5 x 10^24 |
| 32 | 256 | 64 | 43 | 52 | 1.5 x 10^34 |
| 48 | 384 | 96 | 64 | 77 | 2.8 x 10^53 |
| 64 | 512 | 128 | 86 | 103 | 5.2 x 10^72 |
Hex, base64, base64url or base32: which encoding fits?
Base64 uses A to Z, a to z, 0 to 9, plus and slash, and groups 3 bytes into 4 characters. The URL safe variant swaps plus for a minus sign and slash for a low line (_), so a token can sit in a link or a file name without escaping. Base32 uses A to Z and 2 to 7, turns 5 bytes into 8 characters and uses only the digits 2 to 7, so 0 and 1 never sit beside O and I, which is handy when a person must read a token aloud. Hex is the longest but the simplest to check by eye. RFC 4648 defines the alphabets, and says padding with an equals sign is required unless the format you follow says otherwise, which is why the page lets you keep it or drop it.
A byte count that does not divide evenly leaves a partial last character. A 32 byte token has 256 bits, and base64url writes them as 43 characters, where the last character carries only 4 bits of data and 2 zero bits.
| Encoding | Symbols | Bits per character | Characters per byte | Length of 32 bytes |
|---|---|---|---|---|
| Hex | 16 | 4 | 2.00 | 64 |
| Base64 | 64 | 6 | 1.33 | 43 |
| Base64url | 64 | 6 | 1.33 | 43 |
| Base32 | 32 | 5 | 1.60 | 52 |
Other generators on this site suit other jobs: the random string generator builds strings from characters you choose, the random hex generator counts in hex digits, the UUID generator makes standard identifiers, and the password generator is the one for logins.
Can I use a token from a random token generator as a real secret?
The bytes come from the secure generator and leave nothing behind, so the token is as random as the browser can make it. The weak point is everything around it: a secret shown on a screen can be seen, copied from a clipboard history or captured by an extension. For test data, local development and one-off values the page is fine. For a secret that guards live data, the safest place to generate it is the machine or service that will store it.
Use it with
- Random Hex Generator: template-based generators with live preview and copy.
- Random String Generator: template-based generators with live preview and copy.
- Password Generator: strong random passwords.
Questions
How do I generate a random token?
Choose the bytes of randomness and an encoding, then read the list. 16 bytes written in base64url gives 22 characters and 128 bits. Press Generate again for a new set.
How many bytes should a token have?
It depends on the use. 16 bytes (128 bits) is common for identifiers that must never clash, and 32 bytes (256 bits) gives a very large margin. Follow the requirement of the system the token belongs to.
What is the difference between base64 and base64url?
Base64url writes a minus sign and a low line where base64 writes plus and slash, so the token is safe in a link or file name. The bytes are identical.
Do I need the equals padding?
RFC 4648 asks for padding unless the format you follow says otherwise. Many token formats skip it. Tick Keep = padding only when your parser expects it.
Are two tokens ever the same?
Inside one batch never. Across batches a repeat is possible but extremely unlikely at 128 bits or more. The detail lines show the exact figures for your length.
Is the token stored or sent anywhere?
No. It is made in the page, shown to you, and gone when you close or reload it. Copy it before you leave if you need it.
The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.