Random Hex String Generator – Create Secure Hex Values Online
Use the Random Hex String Generator above when you need unpredictable hexadecimal data without writing a script or opening a terminal.
Choose the length in bytes or hexadecimal characters, generate one value or a batch, switch between lowercase and uppercase, add a prefix, insert byte separators and export the result in the format your code or configuration expects.
The generator uses the browser’s cryptographically strong random-number source rather than Math.random(). Generation happens locally.
Hex is simple, portable and easy to inspect, which makes it useful for random tokens, test secrets, identifiers, salts, fixtures and any system that explicitly expects raw random data represented in hexadecimal.
What Is a Random Hex String?
A hexadecimal string uses 16 possible symbols:
0 1 2 3 4 5 6 7 8 9 a b c d e f
Each hex character represents four bits.
Two hex characters represent one byte.
For example:
a4
is one byte written in hexadecimal.
A 32-byte random value therefore becomes 64 hexadecimal characters.
This relationship matters because software specifications sometimes describe a required length in bytes, while a configuration file may expect that value as a hex string.
If you confuse those units, you can accidentally generate a value with half—or twice—the intended entropy.
Bytes vs Hex Characters
Use this quick conversion:
| Bytes | Bits | Hex Characters |
|---|---|---|
| 8 | 64 | 16 |
| 16 | 128 | 32 |
| 24 | 192 | 48 |
| 32 | 256 | 64 |
| 48 | 384 | 96 |
| 64 | 512 | 128 |
The formula is:
hex characters = bytes × 2
and:
bits = bytes × 8
If a library asks for a “32-byte secret,” generate 32 bytes, which appears as 64 hex characters.
If it asks for a “32-character hex string,” that represents only 16 bytes.
The tool lets you choose which unit you mean so there is less room for this common mistake.
How to Use This Random Hex Generator
Start with a preset if your use case matches one.
Otherwise, select Bytes or Hex characters and enter the exact length required by your application.
Choose how many strings to generate.
Select lowercase or uppercase. Hex values are numerically equivalent regardless of case, but some APIs and test suites expect one representation consistently.
Add a prefix if your application uses one.
You can also insert a separator between bytes for output such as:
4a:91:0f:c2
instead of:
4a910fc2
Finally, choose the export format and generate the values.
The Strength tab shows how the selected length relates to raw entropy, while Generate in Code provides equivalent approaches for common programming environments.
How Much Entropy Is in a Hex String?
If every hex character is generated uniformly and independently, each character represents four bits of entropy.
So:
- 16 hex characters = 64 bits
- 32 hex characters = 128 bits
- 48 hex characters = 192 bits
- 64 hex characters = 256 bits
A prefix such as key_ does not add entropy if it is predictable.
Separators do not add entropy either.
Only the random portion counts.
This is why a value like:
secret_ + 32 random hex characters
still contains 128 random bits, not more simply because the displayed string is longer.
Why Cryptographically Secure Randomness Matters
There is a large difference between “looks random” and “is generated from a cryptographically strong source.”
Math.random() is designed for general-purpose pseudo-random behavior, not for security-sensitive secret generation.
The browser Web Crypto API provides crypto.getRandomValues(), which is designed to fill typed arrays with cryptographically strong random values.
That is the source used by this tool.
For random tokens and raw secret material, this is a much stronger foundation than concatenating timestamps or relying on ordinary pseudo-random functions.
When a cryptographic protocol defines how an actual algorithm key must be generated, follow that protocol or use the platform’s dedicated key-generation API rather than inventing your own key format.
What Are Random Hex Strings Used For?
Common uses include random application secrets, test tokens, permitted nonces, salts, webhook test values, seed data, fixtures, random filenames and example configuration.
The right length depends on the purpose.
Do not assume every use needs 256 bits, and do not assume a short value is safe merely because it contains letters and numbers.
If another library or protocol defines an exact size, follow that requirement.
Hex vs Base64
Hex and Base64 can represent the same raw bytes.
The difference is encoding density.
Hex uses two characters per byte.
Base64 uses roughly four characters for every three bytes, making it more compact.
For 32 random bytes:
- Hex: 64 characters
- Base64: usually 44 characters including padding
- Base64URL: similar compactness with URL-friendly substitutions
Hex is often easier to read and debug.
Base64 is more compact.
Use the Random Byte Generator when you want to generate one byte sequence and compare its hex, Base64, Base64URL and code representations.
Prefixes: Useful but Not Random
Prefixes make values easier to identify.
Examples:
test_ token_ secret_ dev_
A good prefix can tell a developer what a value is for before they inspect the surrounding configuration.
It can also help secret scanners or validation code classify credentials.
But prefixes are normally predictable.
Do not include them when calculating entropy.
If a token format requires 32 random bytes plus a fixed prefix, generate the full 32 random bytes first and then add the prefix.
Random Hex String vs NanoID
These tools solve different problems.
A random hex string uses only 16 symbols and is ideal when a system explicitly expects hexadecimal data.
NanoID uses a larger default alphabet, so it can encode more entropy in fewer characters.
For example, 32 hex characters represent 128 bits.
A NanoID character from a 64-symbol alphabet can carry six bits when uniformly selected.
Choose random hex when compatibility, byte representation or cryptographic tooling expects hex.
Choose NanoID when you want a compact URL-safe identifier rather than raw bytes written in hexadecimal. See the NanoID Generator.
Random Hex vs UUID
A UUID is not simply an arbitrary random hex string.
UUID formats contain version and variant bits, follow a standardized layout and have a conventional textual representation.
If an API expects a UUID, use the UUID v7 Generator or an appropriate UUID implementation.
If it expects “32 random bytes encoded as hex,” use this tool.
Generating the right amount of randomness in the wrong format can still cause validation failures.
Always match the format the receiving system documents.
Can You Use Random Hex as a Secret?
A securely generated random hex value can be suitable as secret material when the system you are configuring expects an opaque random token of that size.
But “secret” covers many different things.
An API token, HMAC secret, encryption key and password are not interchangeable simply because they are all secret strings.
For cryptographic algorithm keys, use the generation mechanism required by the algorithm or library.
For third-party API credentials, use credentials issued by that provider.
For documentation and screenshots where you need a realistic but intentionally fake credential, use the Dummy API Key Generator instead.
Handling Generated Secrets Safely
If a generated value will be used as a real secret:
- Do not paste it into public chat
- Do not commit it to a repository
- Avoid logging it
- Store it in a secrets manager or protected environment
- Limit who can read it
- Rotate it if exposure is suspected
Browser-side generation helps avoid sending the random value to the generator’s server, but security does not end at generation.
The clipboard, screenshots, terminal history and configuration files can all expose a secret afterward.
Common Random Hex Mistakes
Watch for these problems:
- Confusing bytes with hex characters
- Counting a fixed prefix as random entropy
- Using Math.random() for sensitive values
- Generating the wrong number of bytes for a protocol
- Adding separators when continuous hex is required
- Treating uppercase and lowercase as different byte values
- Using random hex when a standardized UUID is required
- Publishing a real generated secret in documentation
- Assuming every cryptographic key can be created as arbitrary raw bytes
The safest workflow is to start from the requirement: exact byte length, encoding and purpose.