Skip to content
ZeroKit
guide5 min read·

Base64 is not encryption (and what it is actually for)

Base64 shows up everywhere: data URLs, email attachments, API keys, bearer tokens. It is also widely mistaken for a security measure. This is a short guide to what the encoding does and where it belongs.

01What the encoding actually does

Base64 maps every 3 bytes of binary data to 4 ASCII characters. The alphabet is 64 characters — A–Z, a–z, 0–9, plus and slash — which is why it can travel through text-only channels (JSON strings, XML, email headers, URLs with care) without corruption.

There is no key and no secret. Decoding is a table lookup. Anyone who intercepts a Base64 string can read it in milliseconds, with the same tool you used to encode it.

Try the free Base64 Encoder

02The 33% tax

Four characters carry three bytes, so Base64 output is roughly 4/3 the size of the input, plus padding. Embedding a 2 MB image as a data URL adds about 700 KB. That matters for page weight, mobile data and API payload limits — a base64-encoded binary in JSON is often the reason a request mysteriously hits a size cap.

03URL-safe Base64 exists for a reason

Standard Base64 uses + and /, which have their own meanings inside URLs and filenames. URL-safe Base64 swaps them for - and _, and usually drops the = padding. If you are putting an encoded value into a path segment, query string, or JWT, use the URL-safe variant; otherwise the value will be re-encoded by the next layer and stop matching.

04Where Base64 is the right tool

Legitimate uses are everywhere once you know the constraint is transport, not secrecy:

  • Data URLs for small inline images, icons and fonts in CSS or HTML.
  • Email attachments (MIME) and other protocols that only carry text.
  • Embedding small binary blobs in JSON, where a string is the only available type.
  • JWT segments and other signed envelopes that need a URL-safe binary representation.

05Where it is not

Never store passwords with Base64, never treat an encoded API key as protected, and never rely on obscurity as access control. If data must be unreadable, use encryption with a real key (AES-GCM, libsodium) and keep the key out of the client. If data must be tamper-proof, use a signature or an HMAC and verify it before trusting anything inside.

A practical test: if an attacker who reads your Base64 string would learn something useful, you have a design problem — not an encoding problem.

References

Written for ZeroKit. Every tool mentioned here runs locally in your browser — nothing you paste is uploaded.

Related tools