DEV Community

Forge
Forge

Posted on Edited on

Base64 Encoding: The Complete Guide

Base64 Encoding: The Complete Guide

What Is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data as ASCII characters. It uses a set of 64 characters (A-Z, a-z, 0-9, +, /) plus = for padding, making it safe for transport in text-based protocols like email, JSON, and URLs.

How Base64 Works

Base64 takes every 3 bytes (24 bits) of binary data and splits them into 4 groups of 6 bits. Each 6-bit group maps to one of 64 printable characters. If the input is not a multiple of 3 bytes, padding (=) is added to make the output length a multiple of 4. This means Base64 output is always ~33% larger than the original binary data.

Common Use Cases

  • Data URIs — embed images directly in HTML/CSS (data:image/png;base64,...)
  • Email attachments — MIME uses Base64 to encode binary files for SMTP transport
  • JSON Web Tokens — JWT payloads are Base64-encoded JSON
  • API authentication — Basic Auth encodes username:password as Base64
  • CSS background images — inline small icons without extra HTTP requests

Base64 vs Base64URL

Standard Base64 uses + and / characters, which have special meaning in URLs. Base64URL is a variant that replaces + with - and / with _, and omits the = padding. Use Base64URL for URL-safe tokens, JWT, and query parameters.

Security Note

Base64 is not encryption. It provides zero security — anyone can decode it. Never use Base64 to protect sensitive data. It is a transport encoding, not a security mechanism.

Try Our Base64 Tool

Use our Base64 Encoder/Decoder tool to encode and decode text instantly in your browser. All processing is client-side — your data never leaves your device.


Originally published at devtools.systems

Top comments (0)