DevToolNow

Base64 vs Base32 vs Base58: Encoding Comparison and When to Use Each

DevToolNow Editorial Team··~9 min read

Three encodings, three different optimization targets. Base64 maximizes density, Base32 maximizes typability, Base58 maximizes copy-paste safety. Picking the wrong one creates real bugs — Base64 in a URL gets mangled, Base58 in a JWT breaks parsers, Base32 in a database wastes 30% of bytes for no reason.

1. Quick comparison

EncodingAlphabet sizeBits per charOverheadSpec
Base6464633%RFC 4648 §4
Base64URL64633%RFC 4648 §5
Base3232560%RFC 4648 §6
Base5858~5.86~37%Satoshi 2009
Hex (Base16)164100%RFC 4648 §8

2. Base64 — the default

Standard alphabet: A-Z, a-z, 0-9, +, / with = padding.

The math: 3 bytes (24 bits) → 4 Base64 characters (4 × 6 = 24 bits). 33% size overhead.

Use Base64 when:

  • Embedding binary in JSON, XML, or email (MIME attachments, RFC 2045)
  • Storing small binary blobs in databases that prefer text
  • Encoding data URLs (data:image/png;base64,...)
  • Wherever bandwidth matters and the transport is text-only

Avoid Base64 when:

  • Putting data in URLs — use Base64URL instead
  • Humans will read or type the value — use Base58 or Base32
  • Filenames or file paths — / breaks them

3. Base64URL — the URL-safe variant

Same as Base64 but: +-, /_, padding = usually omitted. RFC 4648 §5.

This is what JWTs use:

// JWT structure: three Base64URL-encoded parts joined by "."
header.payload.signature

eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0In0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Spotting Base64 vs Base64URL: if you see + or / or =, it's standard Base64. If you see - or _ and no padding, it's Base64URL.

4. Base32 — typeable by humans

Standard alphabet (RFC 4648 §6): A-Z, 2-7. Note the absence of 0, 1, 8, 9 and lowercase letters — designed for case-insensitive use and visual disambiguation.

The math: 5 bytes (40 bits) → 8 Base32 characters (8 × 5 = 40 bits). 60% overhead.

Use Base32 when:

  • Human-typed secrets (TOTP / Google Authenticator setup keys)
  • Onion addresses (Tor v3: 56-character Base32)
  • Filenames where case-insensitive filesystems exist (Windows, macOS HFS+)
  • DNS labels (DNS is case-insensitive; Base32 fits)

The 60% overhead is the cost of avoiding lowercase, digits 0/1, and punctuation. For data only machines see, Base64 is more efficient.

5. Base58 — Bitcoin's design

Alphabet: full 64-char Base64 minus 0, O, I, l, +, /. The choices are deliberate:

  • 0 and O — zero vs capital O ambiguity
  • I and l — capital I vs lowercase L ambiguity
  • + and / — URL/path/shell unsafe

The math: 58 isn't a power of 2, so Base58 doesn't have a fixed bytes-per-char ratio. Encoding requires arbitrary-precision arithmetic (treating bytes as a single big integer and dividing by 58 repeatedly). On average, 137 chars per 100 bytes (~37% overhead).

Use Base58 when:

  • Identifiers humans copy-paste (cryptocurrency addresses, IPFS CIDs)
  • Short URLs or invitation codes (https://example.com/i/4Cax2pq)
  • Database IDs that may appear in URLs (Mastodon uses Base58 for status IDs)

Bitcoin actually uses Base58Check: Base58 + 4-byte SHA-256 checksum. Catches typos before sending coins to a wrong address. Modern Bitcoin (SegWit) moved to Bech32 for stronger error detection — see RFC equivalent BIP 173.

6. Real-world encoding choices

SystemEncodingWhy
JWTBase64URLGoes in HTTP headers and URLs
MIME email attachmentsBase647-bit ASCII transport
Bitcoin Legacy addressBase58CheckHuman copy-paste + checksum
Bitcoin SegWitBech32Stronger checksum, lowercase
TOTP / Google AuthBase32Typeable on phone keyboard
Onion v3Base32Case-insensitive DNS
SHA-256 fingerprintHexHuman-readable debug
UUID v4Hex (with hyphens)Standard format (RFC 4122)
data: URLs (images)Base64URL-safe with mime type

7. Decision rule

  1. Will humans copy-paste this? Base58 (or Bech32 for new systems).
  2. Will humans type this? Base32.
  3. Goes in a URL or HTTP header? Base64URL.
  4. Goes in JSON, email, or arbitrary text? Base64.
  5. Debugging only, humans read but never type? Hex.

FAQ

Q. Why does Bitcoin use Base58 instead of Base64?

A. Base58 (Satoshi's design, 2009) removes characters that are visually ambiguous: 0/O, I/l, +, /. The result is that addresses can be read aloud, written by hand, and copied without errors. Base64 includes / which has special meaning in URLs, file paths, and shell commands — bad for human-handled identifiers.

Q. What's the difference between Base64 and Base64URL?

A. Base64 uses + and / in its alphabet. Both are problematic in URLs (+ becomes space, / is a path separator). Base64URL (RFC 4648 §5) replaces + with - and / with _, and the padding = is often dropped. JWTs use Base64URL specifically so tokens can appear in URL query parameters without further encoding.

Q. Why does TOTP (Google Authenticator) use Base32?

A. TOTP secrets are intended to be typed by humans into authenticator apps as a fallback when QR codes fail. Base32's 32-character alphabet (A-Z + 2-7) is case-insensitive, lacks visually ambiguous characters (0, 1, 8, 9), and is friendlier on mobile keyboards than Base64. Trade-off: Base32 expands by 60% (vs Base64's 33%), so TOTP secrets are longer, but they're rarely typed.

Q. Is Bech32 better than Base58?

A. Yes, for human-typed identifiers. Bech32 (BIP 173, used by Bitcoin SegWit and Cardano) adds a checksum that detects single-character errors with 99.99%+ probability. Base58 has no built-in checksum (Bitcoin layered Base58Check on top). Bech32 is also case-insensitive (lowercase only, prevented from mixing). Modern blockchain projects standardize on Bech32 or Bech32m for new addresses.

Q. When should I prefer hex over Base64?

A. Hex when the audience is humans (debug logs, error messages, hash fingerprints — SHA-256 hashes are typically displayed in hex). Hex is unambiguous and trivially readable. Base64 when the audience is machines and bandwidth/storage matters — Base64 is 33% overhead, hex is 100% (each byte becomes 2 chars).

References

About the DevToolNow Editorial Team

DevToolNow's editorial team is made up of working software developers who use these tools every day. Every guide is reviewed against primary sources — IETF RFCs, W3C/WHATWG specifications, MDN Web Docs, and project repositories on GitHub — before publication. We update articles when standards change so the guidance stays current.

Sources we cite: IETF RFCs · MDN Web Docs · WHATWG · ECMAScript spec · Official project READMEs on GitHub