Guide

What is Base64? Encoding Explained with Examples

Base64 encodes binary data as ASCII text so it can be safely transmitted over systems that only handle text. Learn how Base64 encoding works, why it exists, common use cases like data URIs and JWTs, and how to decode Base64 strings.

The one-sentence explanation

Base64 converts binary data (bytes) into a string of 64 printable characters so it can be safely embedded anywhere that only accepts plain text — email, JSON, HTML, URLs, and HTTP headers.

Why does Base64 exist?

Many older protocols and systems were designed for 7-bit ASCII text. Binary data (images, files, cryptographic keys) contains byte values that these systems interpret as control characters, causing corruption or truncation. Base64 sidesteps this by mapping every 3 bytes of binary data into 4 printable ASCII characters — none of which are control characters.

The 64 characters used are: A–Z, a–z, 0–9, +, / (with = as padding). URL-safe Base64 replaces + with - and / with _.

How encoding works

Base64 takes 3 bytes (24 bits) at a time and splits them into four 6-bit groups. Each 6-bit group maps to one of the 64 characters in the alphabet.

Example: encoding "Man"
ASCII bytes: 77 (M) · 97 (a) · 110 (n)
Binary: 01001101 · 01100001 · 01101110
6-bit groups: 010011 · 010110 · 000101 · 101110
Base64 chars: T W F u
"Man" → "TWFu"

If the input length isn't divisible by 3, = padding characters are appended to make the output length a multiple of 4.

Common real-world uses

  • Email attachments (MIME) — email was designed for 7-bit text. SMTP encodes attachments as Base64 so binary files survive transit.
  • Data URIs in HTML/CSS — embed images directly in HTML without a separate HTTP request: src="data:image/png;base64,iVBORw0KGgo..."
  • JSON Web Tokens (JWT) — a JWT is three Base64url-encoded sections separated by dots: header.payload.signature. The payload is not encrypted — just encoded — so never put secrets in a JWT payload.
  • Basic HTTP authentication — the Authorization: Basic header sends username:password as Base64.
  • Cryptographic keys and certificates — PEM format (the -----BEGIN CERTIFICATE----- files) is Base64-encoded DER binary.

Base64 is not encryption

⚠ Common misconception: Base64 provides zero security. Anyone can decode it in seconds. It is purely an encoding scheme for safe text transport, not a way to hide or protect data.

Size overhead

Base64 output is always approximately 33% larger than the input (3 bytes become 4 characters). A 1 MB image becomes roughly 1.37 MB as Base64. This is the trade-off for text-safe transport.

Base64 vs hex encoding

PropertyBase64Hex
Characters used64 (A–Z, a–z, 0–9, +, /)16 (0–9, a–f)
Size overhead~33%~100%
URL safe?⚠ No (use Base64url)✓ Yes
Human readable?NoSomewhat
Common forFiles, images, JWT, emailHashes, byte dumps, colours

Encode or decode Base64 instantly

Paste any text or Base64 string and convert in one click

Open Base64 Encoder →