Home/IDs & Random/Random Byte Generator

Random Byte Generator

Generate cryptographically secure random bytes and drop them straight into your language of choice — hex, Base64, C array, Python bytes, Go slice or raw binary.

Free Browser-based No signup Copy-ready
Generator Settings
Options
Random Bytes
bytes.txt

      
Bytes come from the operating system CSPRNG via crypto.getRandomValues(). Generation is local — no request is made, and nothing is stored.

How it works

1

Choose a byte count

Presets cover AES keys, GCM nonces, salts and HMAC secrets.

2

Pick an output format

Seven encodings and eight source-code formats, all describing the same bytes.

3

Copy or download

Copy the snippet, save as text, or download the raw .bin file.

Sizing key material correctly

Cryptographic primitives specify their inputs in bytes, and getting the size wrong is not a style issue — an AES-256 implementation handed 16 bytes either throws or silently pads, and a reused GCM nonce destroys the confidentiality of every message encrypted under that key.

Reference sizes

  • 12 bytes — AES-GCM nonce. Unique per message, never reused with the same key.
  • 16 bytes — AES-128 key, CBC IV, password salt.
  • 24 bytes — XChaCha20 nonce.
  • 32 bytes — AES-256 key, HMAC-SHA256 secret, session token.
  • 64 bytes — HMAC-SHA512, JWT signing secrets.

Encoding, briefly

  • Hex — 2 characters per byte. Readable, safe everywhere, longest.
  • Base64 — ~1.33 characters per byte. Contains +, / and =, which need escaping in URLs.
  • Base64URL — same density, uses - and _ and drops padding. The right choice for tokens in URLs.
  • Raw binary — no expansion at all. Use for key files, never for anything pasted into a text field.
Nonces are not secrets, but they must be unique. Generating a fresh random nonce per message is correct. Hard-coding one from this page into your source is the single most common way to break AES-GCM in production.
Every mainstream OS exposes a CSPRNG seeded from hardware entropy — getrandom() on Linux, BCryptGenRandom on Windows. crypto.getRandomValues(), which this page uses, is a thin wrapper over it. There is no reason to write your own.

Frequently Asked Questions

View all FAQs
How many bits are in one byte?
Eight bits.
How many random bytes are 256 bits?
32 bytes.
How long is 32 bytes in hex?
64 hexadecimal characters.
Is Base64 more secure than hex?
No. If both encode the same random bytes, the entropy is identical. Base64 is simply more compact.
Can I download actual binary bytes?
Yes. Use the .bin download option when you need the raw byte sequence rather than a text encoding.
Is this generator cryptographically secure?
It uses the browser’s cryptographically strong random-number API for generation.
Should I use random bytes to create encryption keys?
Use the dedicated key-generation mechanism required by your cryptographic library or algorithm. Raw random bytes are appropriate only when the protocol explicitly calls for them.
Is this random byte generator free?
Yes. Generate, encode, copy and download random bytes above without creating an account.

Random Byte Generator – Create Secure Random Bytes Online

Use the Random Byte Generator above when you need raw randomness first and the text format second.

Choose the number of bytes, generate one set or several, then view the same data as hex, Base64, Base64URL, decimal bytes or code-ready arrays. You can also download the generated bytes as a true binary .bin file.

The important point is that encoding does not change the randomness.

Sixteen random bytes are still 128 random bits whether you display them as 32 hex characters, a Base64 string or a programming-language byte array.

This tool generates the bytes locally with the browser’s cryptographically strong random-number source.

What Are Random Bytes?

A byte is eight bits.

A random byte can have any value from 0 through 255.

When bytes are generated uniformly, every possible byte value has the same probability.

Raw bytes are the foundation underneath many values developers think of as strings.

Hex, Base64 and Base64URL are simply different ways of representing those same bytes as text.

That distinction matters whenever an API says “generate 32 bytes” rather than “generate a 32-character string.”

Those are not the same requirement.

How to Use This Random Byte Generator

Set the byte count.

Common sizes include 8, 16, 24, 32, 48 and 64 bytes.

Choose how many sets you need.

Next, select the output format.

If you are pasting the value into a configuration file, hex or Base64 may be easiest.

If you are writing source code, choose an array or language-specific format.

Enable uppercase hex when required, wrap long lines for readability and include a variable declaration if you want a complete copy-ready statement.

The All encodings view lets you compare several representations of the exact same byte sequence.

For genuinely raw output, download the .bin file.

Random Bytes, Bits and Entropy

The conversion is simple:

bits = bytes × 8

Examples:

BytesBits
864
16128
24192
32256
48384
64512

If 32 bytes are generated uniformly from a cryptographically strong source, the raw output contains 256 bits.

Changing the encoding does not increase that number.

A longer Base64 or hex representation is not “more random.” It is simply text encoding overhead.

Likewise, adding a variable name or prefix contributes no entropy when that text is predictable.

Why Use a Cryptographically Strong Random Source?

Security-sensitive randomness should not come from ordinary convenience functions.

The Web Crypto API exposes crypto.getRandomValues(), which fills integer arrays with cryptographically strong random values.

This tool uses that browser capability.

It does not build random bytes from timestamps, counters or Math.random().

That makes the output appropriate as raw unpredictable material for many developer workflows where an application explicitly requires random bytes.

When an encryption or signing algorithm has a dedicated key-generation function, use that official API for the actual cryptographic key rather than manually substituting arbitrary bytes.

The exact protocol requirement comes first.

Hex vs Base64 vs Base64URL

All three can represent the same underlying bytes.

Hex

Hex uses two characters per byte.

32 bytes become 64 hex characters.

It is easy to inspect and widely supported.

Base64

Base64 is more compact.

Three input bytes are normally represented by four Base64 characters, with padding used when necessary.

It commonly contains +, / and =.

Base64URL

Base64URL adapts Base64 for URLs and filenames, typically using - and _ instead of + and /.

Padding handling depends on the consuming system.

Choose the encoding your application expects.

Do not switch formats merely to make the value shorter if the receiving system defines a specific encoding.

Raw Binary vs Text Encoding

Sometimes a system does not want a text representation at all.

It wants the exact byte sequence.

That is where the binary download is useful.

Suppose you generate four bytes:

255, 0, 16, 42

A hexadecimal text file might contain:

ff00102a

A raw binary file contains the four byte values themselves.

Those are different files even though they represent the same data conceptually.

If a tool expects a binary key file, test vector or byte fixture, do not give it the ASCII characters of a hex string unless the documentation specifically asks for hex.

What Are Random Bytes Used For?

Random bytes appear in test secrets, nonces, salts, appropriate initialization vectors, opaque tokens, binary fixtures, protocol tests, fuzzing inputs and key-derivation inputs.

The required size depends entirely on the protocol or application.

One algorithm may require a 12-byte nonce while another format may require 16 bytes.

More bytes are not automatically better if the protocol expects an exact length.

Random Bytes vs Random Hex Strings

A random hex string is random bytes displayed in hexadecimal.

If you generate 32 random bytes, the equivalent hex representation is 64 characters.

The Random Hex String Generator is convenient when hexadecimal is the final format you know you need.

Use this Random Byte Generator when you want flexibility between hex, Base64, Base64URL, decimal arrays, language-specific code and raw binary.

Both can start from the same secure random source.

The difference is how you want to consume the output.

Random Bytes vs API Keys

An API key is an application credential format.

Random bytes are raw entropy.

If you are building your own opaque token system, random bytes may be one component of a secure design.

But a third-party service such as a payment, cloud or AI provider issues its own credentials. You cannot generate a working provider key simply by creating the right number of random bytes.

For docs, UI mockups and test fixtures where you need a key-shaped value that authenticates nothing, use the Dummy API Key Generator.

For real provider access, create and manage the credential in the provider’s own system.

Random Bytes vs UUIDs and NanoIDs

UUIDs and NanoIDs are higher-level identifier formats.

They define how random or structured data is arranged and represented.

Random bytes do not carry that structure.

Use UUID v7 when you need a standardized UUID with a timestamp.

Use NanoID when you need a compact URL-safe random identifier with configurable length and alphabet.

Use raw bytes when the application explicitly asks for bytes, a cryptographic input, a binary fixture or an encoding derived from random data.

Choosing the right tool avoids format-conversion bugs later.

How Many Random Bytes Do You Need?

There is no universal answer.

The correct size comes from the system consuming the value.

If a specification says 16 bytes, generate 16 bytes.

If it says 256 bits, generate 32 bytes.

If it expects a 96-bit nonce, that is 12 bytes.

Do not confuse bit length, byte length and encoded text length.

Use:

bytes = bits ÷ 8

For hex:

hex characters = bytes × 2

Base64 follows different text-length rules and may include padding.

Security Does Not Stop at Generation

Local generation protects one part of the workflow: the tool does not need to transmit your random bytes to create them.

Once you copy a value, you control where it goes.

If it is sensitive:

  • Keep it out of public repositories
  • Avoid screenshots
  • Do not paste it into issue trackers
  • Limit logging
  • Store it in appropriate secret storage
  • Rotate it if you suspect disclosure

A perfectly random secret can still be compromised by poor handling.

For public documentation, use intentionally fake placeholders instead of real random production values.

Common Random Byte Mistakes

Common errors include:

  • Generating characters when the requirement says bytes
  • Treating hex and Base64 lengths as equivalent
  • Using Math.random() for sensitive random material
  • Giving a binary consumer a text file
  • Changing Base64 to Base64URL without checking the format
  • Adding or removing Base64 padding arbitrarily
  • Generating the wrong nonce or IV size
  • Hard-coding real secrets into source
  • Assuming arbitrary random bytes are always the right way to create an algorithm key

Start with the protocol requirement, then generate exactly the number of bytes and encoding it specifies.

Related searches

random byte generatorcrypto.getRandomValues bytesrandom bytes to hexrandom bytes base64binary bin file generatorrandom nonce iv generatorsecure random bytes onlinerandom bytes vs base64urlbyte array generator coderandom bytes for encryption key256 bit random bytesrandom bytes entropy