encoding · level 3

Base64

Binary-safe text with a 6-bit trick.

150 XP

Base64

You have a binary file — an image, a signed token, a cryptographic key. You need to send it somewhere that only accepts text. Base64 solves this. It turns arbitrary bytes into plain ASCII text using just 64 characters: A-Z, a-z, 0-9, +, /.

Analogy

Imagine you need to ship a sofa through a doorway that only admits flat, rectangular boxes. The sofa itself is fine, but the doorway refuses anything it doesn't recognise. So you disassemble the sofa into flat panels, each a uniform shape that slides through easily, and the person on the other side reassembles it into the original piece. Base64 does the same thing for arbitrary bytes passing through text-only channels like email bodies or URL parameters — and, like flat-packing furniture, the disassembled version takes up a bit more space than the original.

The 6-bit trick

A byte is 8 bits. Base64 works in 6-bit groups — because 2^6 = 64. So Base64 takes 3 bytes (24 bits) and splits them into 4 six-bit groups. The result is always one-third larger than input.

Padding with =

If the input length isn't a multiple of 3, Base64 pads the output with =.

Still not encryption

Base64 is often mistaken for encryption because it looks like gibberish. It is not.

Tools in the wild

5 tools
  • Standard `base64` / `base64 -d` CLI on every Unix system; piped into curl all the time.

    cli
  • CyberCheffree tier

    GCHQ's browser tool — base64-then-base64url-then-deflate chains in one place.

    service
  • Node Bufferfree tier

    `Buffer.from(str).toString('base64')` and `'base64url'` for URL-safe encoding.

    library
  • Python base64free tier

    Standard library: `b64encode`, `b64decode`, `urlsafe_b64encode` for URL variants.

    library
  • jwt.iofree tier

    Decode JWTs (three base64url segments) and inspect headers/claims live.

    service