What is Base64 Encoding? A Simple Explanation

Updated April 2026 · 4 min read

Base64 is one of the most commonly used encoding methods in web development, yet many developers use it without fully understanding what it does or why. This guide explains Base64 in plain language with practical examples.

The Short Answer

Base64 converts binary data into text using 64 safe ASCII characters (A-Z, a-z, 0-9, +, /). This lets you safely transmit binary data through systems that only support text — like email, JSON, URLs, and HTML.

Why Not Just Use the Raw Data?

Many systems were designed to handle text only. Email protocols (SMTP), JSON, XML, and URL parameters cannot safely carry raw binary data. Special characters, null bytes, and non-printable characters would break the transport. Base64 solves this by converting everything into a safe, text-only format.

How It Works (Step by Step)

  1. Take the input data and convert each character to its 8-bit binary representation
  2. Concatenate all the bits into one long binary string
  3. Split into groups of 6 bits (not 8 — this is the key difference)
  4. Map each 6-bit group to one of 64 characters in the Base64 alphabet
  5. Add = padding if the input length is not divisible by 3

Example

Input:    "Hi"
ASCII:    72, 105
Binary:   01001000 01101001
6-bit:    010010 000110 1001xx
Base64:   S      G      k=
Result:   "SGk="
Try the Base64 Encoder/Decoder →

Common Use Cases

1. Data URIs in HTML/CSS

Embed small images directly in your CSS without a separate HTTP request:

background-image: url(data:image/png;base64,iVBORw0KGgo...);

2. Email Attachments

MIME encoding uses Base64 to attach files to emails safely.

3. API Authentication

HTTP Basic Auth encodes username:password as Base64:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

4. JSON Web Tokens (JWT)

JWTs use Base64URL encoding for their header and payload sections.

Base64 is NOT Encryption

A common misconception: Base64 does not protect your data. It is trivially reversible — anyone can decode it instantly. Never use Base64 as a security measure. For actual security, use encryption (AES, RSA) or hashing (SHA-256).

The Size Trade-Off

Base64 encoding increases data size by approximately 33%. Three bytes of input become four bytes of output. This is usually acceptable for small payloads but can be significant for large files.

Related Tools