Base64 vs Base32 vs Base58 vs Base85 vs Hex: Which to Use?
A practical, technical guide to every major binary-to-text encoding: how each works, what it costs in size, when it breaks, and a clear decision tree for choosing the right one.
- guide
- fundamentals
- comparison
- encoding
Binary data lives inside every computer, but the world’s communication channels were built for text. Email, JSON, HTML, URLs, DNS — they all have rules about which bytes are safe, and raw binary routinely breaks them. Binary-to-text encodings solve that mismatch by mapping arbitrary bytes to a subset of printable characters.
There are many such encodings, and the differences matter enormously in practice. Picking the wrong one can mean 40 % size overhead where you need none, broken links, unreadable payloads, or broken copy-paste. This guide covers the five you will actually encounter, with enough depth to make the right call every time.
The encodings at a glance
| Encoding | Alphabet size | Overhead | Characters used | Case-sensitive |
|---|---|---|---|---|
| Hex | 16 | +100 % | 0–9 a–f |
No |
| Base32 | 32 | +60 % | A–Z 2–7 |
No |
| Base64 | 64 | +33 % | A–Z a–z 0–9 + / |
Yes |
| Base64url | 64 | +33 % | A–Z a–z 0–9 - _ |
Yes |
| Base58 | 58 | ~+37 % | 1–9 A–H J–N P–Z a–k m–z |
Yes |
| Base85 (Ascii85) | 85 | +25 % | 85 printable ASCII chars | Yes |
Overhead is the extra bytes added when representing N bytes of binary. The key tradeoff is: bigger alphabet → less overhead, but more special characters → more things that can go wrong.
Hex encoding
How it works
Each byte (0–255) is represented as two hexadecimal digits. One byte → two characters, always, with no padding.
0x48 0x65 0x6C 0x6C 0x6F → "48656c6c6f"
Overhead
Exactly 100 % — every byte doubles. A 1 MB file becomes 2 MB of hex text.
Alphabet
0123456789abcdef (or uppercase ABCDEF). Only 16 safe characters, all of which are unambiguous in every encoding, URL-safe without escaping, and universally renderable.
Where hex is the right choice
- Cryptographic output: SHA-256, SHA-512, BLAKE3, HMAC — every major hash function displays its output as hex because hex is the universal language of bytes.
a591a6d40bf420404…is immediately recognizable as a digest. - Binary file inspection: hex dumps (
xxd,hexdump) let you see every byte position unambiguously. - Color codes in CSS:
#ff6600is hex-encoded RGB. - Low-overhead situations where simplicity beats size: configuration files, logging, debugging, protocol specifications.
- Readability over compactness: hex is the only encoding where a developer can decode it mentally by scanning two characters at a time.
Where hex fails
Anywhere size matters. A Base64-encoded 10 MB image is ~13.3 MB; the same image in hex is 20 MB. For data URIs, email attachments, or any channel with size constraints, hex wastes too much space.
Base32
How it works
Base32 takes 5 bytes (40 bits) at a time and maps each 5-bit group to one of 32 characters. It produces 8 characters per 5 bytes (the standard RFC 4648 alphabet is A–Z and 2–7). Padding with = fills the last group if input isn’t a multiple of 5 bytes.
"Hello" → "JBSWY3DP"
Overhead
+60 % — every 5 bytes become 8 characters.
Alphabet
ABCDEFGHIJKLMNOPQRSTUVWXYZ234567. Only uppercase letters and digits, no lowercase, no symbols. This makes Base32 strings case-insensitive — a critical property for human-facing codes.
Where Base32 is the right choice
- TOTP / HOTP secrets: Every authenticator app (Google Authenticator, Authy) uses Base32 for shared secrets, precisely because users type them by hand across different keyboards. Case-insensitivity eliminates a whole class of user errors.
- DNS labels: DNS is case-insensitive; Base32 survives a round-trip through a DNS resolver without corruption.
- Onion addresses (v3 Tor): the 56-character
.onionaddresses are Base32 encoded. - Human-typed codes: license keys, pairing codes, anything a user must read from a screen and type elsewhere.
JBSWY3DPis harder to misread thanSGVsbG8=.
Where Base32 fails
Anywhere size matters. +60 % overhead is significant. It is also needlessly wasteful for machine-to-machine communication where case doesn’t matter.
Base64
How it works
Base64 takes 3 bytes (24 bits) at a time and maps each 6-bit group to one of 64 characters. It produces 4 characters per 3 bytes. Padding with = fills the last group.
"Hello" → "SGVsbG8="
Overhead
+33 % — the best ratio among the “safe” encodings (encodings that avoid every control character and most punctuation).
Alphabet
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/. The + and / characters cause problems in URLs (they have special URL meanings) and in some file systems.
Base64url solves this by replacing + with - and / with _, making the output safe in URLs, filenames, and HTTP headers without percent-encoding.
Where Base64 is the right choice
- Email attachments (MIME): The original use case. Every email body and attachment you’ve ever sent was Base64-encoded by your mail client.
- Data URIs:
<img src="data:image/png;base64,iVBORw0KGgo…">— the only practical way to inline binary resources in HTML/CSS. - JWT tokens: The header and payload sections of a JSON Web Token are Base64url encoded (note: encoded, not encrypted — they are public).
- HTTP Authorization headers:
Authorization: Basic dXNlcjpwYXNzis Base64. - Binary fields in JSON/XML: Any API that needs to pass binary data (images, audio, arbitrary bytes) through a JSON body uses Base64.
- General-purpose machine-to-machine data: The default choice when you need binary in a text channel and humans won’t type it.
Where Base64 fails
- URLs (use Base64url instead)
- Human-typed codes (use Base32 — Base64 is case-sensitive and uses
+/=which are ambiguous) - Anywhere size is critical (use Base85 for 8 % less overhead)
Base58
How it works
Base58 uses a 58-character alphabet that intentionally omits visually ambiguous characters:
0(zero),O(capital o) — look alikeI(capital i),l(lowercase L) — look alike+and/— special in URLs
The alphabet is: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
Unlike hex, Base32, and Base64, Base58 treats the entire byte string as one large integer and converts it to base 58. This means:
- Leading zero bytes become leading
1s (preserved count) - The output length varies with the value, not just the length — short strings can compress
Overhead
Approximately +37 % on average — slightly worse than Base64, but the character set is designed for human use.
Where Base58 is the right choice
- Cryptocurrency addresses: Bitcoin, Litecoin, Dogecoin, and many others use Base58Check. The design goal was explicitly “shorter addresses that can be copy-pasted without ambiguity.”
- Content-addressed storage: IPFS CIDv0 hashes (
Qm…) are Base58-encoded SHA-256 multihashes. - Any human-facing identifier that must avoid ambiguity: where you want compact encoding but humans may copy by hand.
Where Base58 fails
- Performance-sensitive systems: The big-integer arithmetic is significantly slower than the bitwise shifts used by Base64/Base32.
- Standard libraries: Base58 has no RFC. Support is uneven — you’ll need a third-party library in most languages.
- When you need a standard: Use Base64url instead; it has an RFC, universal support, and is URL-safe.
Base85 (Ascii85)
How it works
Base85 takes 4 bytes (32 bits) at a time and represents them as 5 ASCII characters from a range of 85 printable characters. It produces 5 characters per 4 bytes.
Three main variants exist:
- Ascii85 (Adobe/PostScript/PDF): uses characters
!throughupluszshorthand for all-zero groups, wrapped in<~and~>delimiters. The variant behind PDF’sASCII85Decodefilter and Python’sa85. - RFC 1924 Base85: an 85-character alphabet created for compactly representing IPv6 addresses, later adopted as the “base85” used by Git, Mercurial and Python’s
base64.b85encode. - Z85 (ZeroMQ): the alphabet chosen so its output contains no quotes or backslashes — friendly to C strings and JSON without escaping.
"Hello" → "87cURDZ" (Ascii85)
Overhead
+25 % — 4 bytes become 5 characters. This is the most compact binary-to-text encoding in common use.
Where Base85 is the right choice
- PostScript and PDF: Ascii85 has been used in PDF files since the format’s inception to encode binary streams. In PostScript you’ll see
<~87cURDZ~>framing; inside a PDF’s stream the delimiters are usually omitted — you see bare87cURDZ…betweenstream/endstream. - ZeroMQ binary frames: ZMQ uses Z85 to pass binary keys and certificates as strings in configuration.
- Storing binary in source code or config: When you absolutely cannot accept Base64’s 33 % overhead and can live with the less-universal alphabet.
- Git’s binary diff format: Git uses a Base85 variant to embed binary patches in diff output.
Where Base85 fails
- URL safety: Most Base85 alphabets include characters that must be percent-encoded in URLs.
- Database storage: Many Base85 special characters (
",',\,<,>) cause problems in SQL strings and HTML. - Standard support: Even less universal than Base58. The three alphabets (Ascii85, RFC 1924, Z85) are mutually incompatible.
- Human-typing: The special characters make it unusable for codes that users must type.
The decision tree
Is the output going into a URL or filename?
├── YES → Base64url (RFC 4648, universally supported, URL-safe)
└── NO
│
Will humans type this by hand?
├── YES → Base32 (case-insensitive, no ambiguous chars)
└── NO
│
Is this a crypto/blockchain address or IPFS CID?
├── YES → Base58 (follow the ecosystem standard)
└── NO
│
Is every byte of size critical (PDF, binary diffs)?
├── YES → Base85 (25 % overhead vs 33 %)
└── NO
│
Is this a hash digest, hex dump, or color code?
├── YES → Hex (universally readable, debuggable)
└── NO → Base64 (the universal default)
Size comparison — concrete example
10,000 bytes of binary data:
| Encoding | Output size | vs raw |
|---|---|---|
| Raw binary | 10,000 bytes | — |
| Base85 | 12,500 bytes | +25 % |
| Base64 | 13,336 bytes | +33 % |
| Base58 | ~13,700 bytes | ~+37 % |
| Base32 | 16,000 bytes | +60 % |
| Hex | 20,000 bytes | +100 % |
The ~ on the Base58 row is a caveat, not decoration: leading zero bytes contribute nothing to the big integer, so each is re-emitted as a leading 1 to keep the count, and length behaves irregularly for short inputs — the Base58 section explains why.
Security note: none of these are encryption
Every encoding in this guide is fully reversible without any key or password. They are data representation formats, not cryptographic protection. Base64-encoding a password, a private key, or a secret token does not protect it.
If you need confidentiality: encrypt first (AES-GCM, ChaCha20-Poly1305), then encode the ciphertext for transport. The encoding is packaging, not a lock.
FAQ
Which encoding do browsers and web APIs use by default?
Base64 / Base64url. The btoa() and atob() functions in JavaScript produce standard Base64. The encodeURIComponent function is unrelated — it’s percent-encoding, not Base64.
Can I mix encodings?
You can encode in stages — for example, gzip a payload, then Base64 the compressed bytes — but each stage adds overhead. Mixing is rarely better than choosing the right encoding once.
Why does Base64 output end in = or ==?
Padding. Base64 encodes 3 bytes → 4 characters. If the input isn’t a multiple of 3, padding characters fill the last group to the 4-character boundary. Many implementations accept and produce Base64 without padding when the length is known from context (e.g. JWT).
What is Base62?
A case-sensitive alphanumeric-only encoding (0–9 A–Z a–z). No standard; used mainly for URL shorteners (Bitly links). Overhead is similar to Base64 (~+34 %) but the alphabet is completely URL-safe without any special characters. YouTube video IDs are not Base62, despite the common claim — their 11-character IDs draw from the Base64url alphabet (A–Z a–z 0–9 - _, ≈66 bits).
Is Base64url the same as Base64?
Almost. Base64url replaces + with - and / with _, and usually omits = padding. The encoding and decoding process is otherwise identical. Always prefer Base64url for JWT, OAuth tokens, and anything that will appear in a URL.
Try the Base64 encoder and decoder to see this encoding in action — all processing runs entirely in your browser.
Try it yourself — right now
Both tools run 100% in your browser. Nothing you type or drop is ever uploaded.
Related posts
Related posts
October 28, 2026
Character Sets Explained: How Encoding Detection Works and Why It Matters for Base64
Base64 moves bytes, but characters become bytes through a character set. This guide explains ASCII, Unicode, UTF-8, legacy code pages, CJK and EBCDIC, how auto-detection works, and why picking the wrong charset turns readable text into mojibake.
October 26, 2026
Base64 data URLs: how to embed images in HTML, CSS, JSON and email
A complete, practical guide to data::URLs — when embedding an image inline with Base64 beats a regular request, the bandwidth trade-off nobody sells you, MIME types done right, CSP and email gotchas, and copy-paste syntax for HTML, CSS, SVG, JSON and Python.
October 20, 2026
How to Base64 encode and decode in JavaScript: btoa, atob, Buffer, and Data URLs
A complete, copy-paste-tested guide to Base64 in JavaScript: the btoa/atob basics, the Unicode trap that breaks naive code, TextEncoder done right, Node Buffer equivalents, and Data URL patterns for files.