FormatterHQ

Random Byte Generator

Generate secure random bytes for secret keys, salts, nonces and test vectors. Output them as hex, Base64, decimal, binary or a ready-to-paste array.

Loading tool…
Ready.

How to use the Random Byte Generator

  1. Enter the number of bytes (for example 32 for a 256-bit key).
  2. Choose the output format: hex, Base64, decimal, binary or array.
  3. Optionally separate hex bytes with spaces for readability.
  4. Generate and copy the result into your configuration or code.

Generate raw random bytes for cryptography and testing

The random byte generator asks the browser's Web Crypto API for the number of bytes you request and prints them in the format you need. Unlike a random string, which picks from an alphabet, this gives you the underlying binary data directly, which is what encryption keys, HMAC secrets, salts and nonces actually are.

Common sizes

BytesBitsTypical use
1296AES-GCM nonce (IV)
16128AES-128 key, password salt, CSRF token
32256AES-256 key, HMAC-SHA256 secret, JWT HS256 signing key, app keys
64512HMAC-SHA512 secret

Random byte generator output formats

The same 8 random bytes in each format:

hex      9f3a07c2e15b44d8
base64   nzoHwuFbRNg=
decimal  159 58 7 194 225 91 68 216
array    [0x9f, 0x3a, 0x07, 0xc2, 0xe1, 0x5b, 0x44, 0xd8]
binary   10011111 00111010 00000111 11000010 11100001 01011011 01000100 11011000
  • Hex – two characters per byte; the most common way to store keys in environment variables and config files.
  • Base64 – about 33% shorter than hex. Laravel's APP_KEY, for example, is 32 random bytes encoded in Base64 with a base64: prefix.
  • Decimal – each byte as a number 0–255, handy for teaching or for languages without hex literals.
  • Array – a comma-separated list of 0x.. literals you can paste into C, Java, Rust, Go or JavaScript source code.
  • Binary – eight bits per byte, useful for learning bitwise operations.

Random bytes vs random strings

A random string limited to letters and digits carries about 5.95 bits per character, while a byte carries a full 8 bits. When a library asks for a "32-byte key", it means 32 bytes of raw binary, not 32 typed characters. Generating the bytes directly and then encoding them avoids that confusion: the hex or Base64 text is only a transport format, and your code decodes it back to bytes before use.

The spaced hex option inserts a space between bytes (9f 3a 07 c2), which is easier to read when you compare values with a hexdump or protocol documentation.

Security notes

  • Bytes come from crypto.getRandomValues, a cryptographically secure generator, and never leave your browser.
  • Treat generated keys like passwords: keep them out of source control and rotate them if they leak.
  • Do not use a human-readable password as an encryption key. If you must derive a key from a password, use a key-derivation function such as PBKDF2, scrypt or Argon2.

To convert the result into another representation later, use hex to Base64 or Base64 to hex. For identifiers rather than secrets, a UUID is usually the more convenient format.

Frequently asked questions

How many bytes do I need for a 256-bit key?
You need 32 bytes, because each byte holds 8 bits. In hex that is 64 characters; in Base64 it is 44 characters including padding.
Is Base64 or hex better for storing a key?
Both represent the same bytes. Hex is easier to read and compare, while Base64 is shorter. Use whichever format your framework or library expects.
Are the bytes truly random?
They come from the operating system’s cryptographically secure random source via the Web Crypto API, which is designed for generating keys. They are not predictable from earlier output.
What is the maximum number of bytes?
You can generate up to 65,536 bytes (64 KB) at a time, which is the limit the Web Crypto API allows in a single request.

Last updated October 3, 2026

Related tools

String Byte Size Counter Count how many bytes a string uses in UTF-8, UTF-16 and UTF-32, plus characters, code points and Base64/URL-encoded size. Random Alphanumeric Generator Generate letters-and-digits codes for vouchers, reference IDs and usernames in mixed, upper or lower case. Random Binary Generator Generate random binary numbers (strings of 0s and 1s) of any bit length. Random Color Generator Generate random colours as HEX, RGB or HSL codes with a swatch preview for inspiration and testing. Random CSV Generator Generate realistic fake CSV test data — names, emails, addresses, dates and more — with custom fields. Random Date Generator Generate random dates or date-times between two dates in ISO, US, EU, long, Unix or RFC formats. Random Data from Regex Generate random strings that match a regular expression — ideal for test data such as IDs, codes and formats. Random Decimal Generator Generate random decimal (floating-point) numbers in a range with a fixed number of decimal places. Random Emoji Generator Generate random emoji from smileys, animals, food, travel, objects or symbols to copy and paste. Random Fraction Generator Generate random proper fractions such as 3/7 with a maximum denominator, simplified automatically. Random Hex Generator Generate random hexadecimal numbers and strings of any length, in upper or lower case. Random Integer Generator Generate uniform random integers between inclusive bounds, with negatives, unique draws, sorting and up to 10,000 values.