API Key Format Comparison: Hex vs Base64 vs UUID — Which Should You Use?

Published March 9, 2026 · 7 min read

Choosing the right format for your API keys affects storage efficiency, URL compatibility, developer experience, and even how easily leaked keys can be detected. The three most common formats are hexadecimal, Base64, and UUID. Each has distinct tradeoffs that matter depending on your use case.

This guide compares all three formats across the dimensions that matter most for production API systems.

Quick Comparison Table

PropertyHexBase64urlUUID v4
Characters used0-9, a-fA-Z, a-z, 0-9, -, _0-9, a-f, hyphens
Bits per character464 (with fixed bits)
256-bit key length64 chars43 charsN/A (max 122 bits)
128-bit key length32 chars22 chars36 chars (with hyphens)
URL safeYesYes (url variant)Yes
Case sensitiveNoYesNo
Human readableModeratePoorGood (structured)

Hexadecimal Keys

Hex encoding represents each byte as two characters from the set 0-9a-f. It is the most straightforward encoding and the easiest to reason about in terms of entropy.

// 256 bits of entropy = 64 hex characters
a3f8c1d9e4b72f6a8d1e3c5b7a9f0d2e4c6b8a1f3e5d7c9b0a2d4f6e8c1a3b5d

// 128 bits of entropy = 32 hex characters
a3f8c1d9e4b72f6a8d1e3c5b7a9f0d2e

Pros

Cons

Best for

General-purpose API keys, webhook signing secrets, internal service tokens, and any context where simplicity and debuggability matter more than brevity.

Base64url Keys

Base64 encoding uses 64 characters (A-Z, a-z, 0-9, and two symbols) to represent 6 bits per character. The URL-safe variant (RFC 4648) replaces + with - and / with _, and strips padding = characters.

// 256 bits of entropy = 43 base64url characters
o_jB2eS3L2qNHjxbepnwLeTGuKHzPeV8m0otT26Mobtd

// 128 bits of entropy = 22 base64url characters
o_jB2eS3L2qNHjxbepnwLg

Pros

Cons

Best for

High-throughput APIs where header size matters, mobile applications, JWTs and token-based auth systems, and environments where storage per key is a concern at scale.

UUID v4 Keys

UUID v4 generates 122 random bits formatted as 32 hex digits with 4 hyphens in a standardized pattern: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx. The 4 indicates version 4 and y is constrained to 8, 9, a, or b.

// UUID v4 — always 36 characters, always 122 bits of randomness
f47ac10b-58cc-4372-a567-0e02b2c3d479

Pros

Cons

Best for

Public API identifiers (not secrets), resource IDs, correlation IDs for distributed tracing, database primary keys, and any context where developer familiarity and tooling support outweigh entropy requirements.

Entropy Comparison by Format

The following table shows how many characters each format needs to achieve common entropy targets:

Target EntropyHexBase64urlUUID v4
64 bits16 chars11 charsN/A
128 bits32 chars22 chars36 chars (max ~122)
192 bits48 chars32 charsN/A
256 bits64 chars43 charsN/A

URL Safety Deep Dive

When API keys appear in URLs (query parameters, path segments, or fragments), certain characters cause problems:

If your keys will ever appear in URLs, use hex, base64url, or UUID. Never use standard base64 with + and / characters.

Storage Efficiency

If you store millions of API keys, the per-key storage adds up. For 256 bits of entropy:

At 10 million keys, the difference between hex and base64url is about 200MB. In most systems this is negligible, but it matters for in-memory caches and bandwidth-constrained APIs.

Recommendations by Use Case

REST API Authentication Keys

Use hex or base64url with at least 256 bits. Add a prefix like sk_live_ to identify key type and environment. Hex is simpler; base64url is shorter.

Webhook Signing Secrets

Use hex with 256 bits. Webhook secrets are used in HMAC computations where hex is the standard output format, keeping your codebase consistent.

Public API Identifiers

Use UUID v4. These are not secrets, so the 122-bit entropy ceiling is fine. The standardized format makes integration easier for your consumers.

Distributed System Tokens

Use base64url with 256 bits. The compact encoding reduces overhead in service-to-service communication where tokens appear in every request header.

Short-Lived Session Tokens

Use base64url with 128 bits. These tokens expire quickly, so 128 bits is sufficient, and the shorter length improves cookie size efficiency.

No matter which format you choose, always generate the underlying randomness with a cryptographically secure source like crypto.getRandomValues(). The format is just encoding; security comes from the entropy source. Try our free key generator to create keys in any format instantly.

Recommended Resources

For the theory behind encoding, entropy, and cryptographic randomness, Real-World Cryptography is the best modern reference. To implement secure key formats in JavaScript, JavaScript: The Definitive Guide covers Base64, typed arrays, and the Web Crypto API.

SPUNK LLC Network

API Sites

Key Management

More from SPUNK LLC