Home/IDs & Random/Random Hex String Generator

Random Hex String Generator

Cryptographically secure random hex — sized in bytes or characters, with the prefixes, casing and separators each format actually needs.

Free Browser-based No signup Copy-ready
Generator Settings
Generated Strings
hex.txt

      
Generated locally with crypto.getRandomValues(). Nothing leaves your browser, so these are safe to use as real secrets — but rotate anything you paste into a shared screen or chat.

How it works

1

Pick a preset or a length

AES key, session token, salt, MAC address or hex colour — the sizing is done for you.

2

Check the strength tab

See how many bits you actually have and whether that is enough for the job.

3

Export

Copy one, copy all, or emit ready-to-paste .env lines.

Bytes, characters and the mistake in between

Hex encodes exactly 4 bits per character, so n bytes always render as 2n characters. This is where a surprising number of security bugs start: a developer asked for "a 32-character key", got 16 bytes of entropy, and shipped half the strength they believed they had. Specify secrets in bytes and let the encoding follow.

Sizes worth memorising

  • 16 bytes — AES-128 key, password salt.
  • 12 bytes — AES-GCM nonce. Never reuse one with the same key.
  • 32 bytes — AES-256 key, session token, HMAC secret. The sensible default for anything secret.
  • 64 bytes — JWT signing secrets where you want extra margin.
  • 3 bytes — a hex colour.

Where hex is the wrong encoding

Hex is readable and universally supported, but it is the least dense common encoding. 32 bytes is 64 hex characters versus 44 in Base64. When the value travels in a URL or a header where length matters, Base64URL is the better choice — the random byte generator emits both.

Hex remains the right call for anything a human will read aloud, diff, or paste into a config file where a stray + or / would cause trouble.

Math.random() is not a secret generator. It is a fast statistical PRNG whose internal state can be recovered from a few outputs. Anything guarding access must come from crypto.getRandomValues(), crypto.randomBytes(), Python's secrets module or an equivalent CSPRNG — which is what this page uses.

Frequently Asked Questions

View all FAQs
How many hex characters are in one byte?
Two. One byte is eight bits and each hex character represents four bits.
How many hex characters are 32 bytes?
64 hexadecimal characters.
Is a 64-character hex string 256 bits?
Yes, if all 64 characters are generated uniformly at random. That represents 32 bytes or 256 bits.
Is this random hex generator cryptographically secure?
It uses the browser’s cryptographically strong random-number API rather than Math.random().
Is uppercase hex more secure than lowercase?
No. Case changes only the representation, not the underlying bytes or entropy.
Can I use the output as an API key?
Use provider-issued keys for real third-party APIs. For your own opaque token system, follow your application’s security design. For documentation placeholders, use the Dummy API Key Generator.
Is this random hex generator free?
Yes. Generate, format, copy and download random hex strings above without creating an account.

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:

BytesBitsHex Characters
86416
1612832
2419248
3225664
4838496
64512128

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.

Related searches

random hex string generatorsecure hex generatorhex bytes converterhex vs base64crypto.getRandomValues hexrandom hex entropyhex string prefixrandom token generator hexhex separator generatorrandom hex noncerandom hex vs uuid256 bit hex string