Understanding Base Encoding (Base64, Base32, Hex) and When Each Matters

A practical guide to Base64, Base32, and hexadecimal encoding—why they exist, how padding works, URL-safe variants, and common mistakes.

· 2 min read ·319 words
  • #encoding
  • #text
  • #developer
  • #conversion
  • #base64

Binary data can’t always travel unchanged. Email bodies, URLs, JSON strings—these channels historically expected text‑safe subsets. Base encodings map arbitrary bytes into safe alphabets with predictable expansion.

Hex vs Base64 vs Base32 (at a glance)

  • Hex (base16): 0–9 a–f. Human‑diffable, verbose (2 chars per byte).
  • Base64: A–Z a–z 0–9 + /. Compact (≈1.33× expansion). Requires padding = signs (unless URL‑safe context tolerant).
  • Base32: A–Z 2–7. Case‑insensitive, avoids visually ambiguous chars. More expansion (≈1.6×) but better for manual transcription.

Why padding?

Base64 processes 3 input bytes → 4 output chars (24 bits → 4×6). If bytes not multiple of 3, = pads to signal truncated quantum. Some modern decoders accept missing padding; strict tools may not.

URL‑safe variants

Base64 URL variant swaps +- and /_. Keep padding for interoperability unless spec says otherwise (e.g. JWT segments omit padding by convention).

Common mistakes

  • Confusing encoding with encryption (Base64 is reversible trivially).
  • Double encoding causing == proliferation.
  • Forgetting to decode before hashing (changes digest!).
  • Copy‑pasting Base64 with line wraps from legacy MIME encoders.

Practical examples

// Hex of bytes
"4869" -> "Hi"

// Base64
SGk= -> "Hi"

// Base32 (RFC 4648)
JBSQ==== -> "Hi"

// URL safe Base64 (no padding example)
SGk -> "Hi" (decoder must infer padding)

When to choose each

  • Hex: Debugging, cryptographic digests (SHA‑256 outputs 64 hex chars).
  • Base64: Embed small binary blobs in JSON / HTML / data URLs.
  • Base32: Human transcription (e.g. TOTP seeds, case‑insensitive contexts).

Related tools

Further tips

Need to embed images inline? Use Base64 but watch size bloat; compression then encoding can still expand relative to raw binary. For large files prefer serving as separate assets with caching. Explore more utilities in our full tool index.

Targets queries: “what is base64”, “base64 vs base32”, “hex encoding explained”, “url safe base64”.