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:
| Bytes | Bits |
|---|---|
| 8 | 64 |
| 16 | 128 |
| 24 | 192 |
| 32 | 256 |
| 48 | 384 |
| 64 | 512 |
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.