Base64 Encoding Explained: How It Works and When to Use It
Back to Articles
Developer Guides

Base64 Encoding Explained: How It Works and When to Use It

Understand Base64 encoding from first principles. Learn why it exists, how the algorithm works step-by-step, and practical use cases for developers.

DailyUtil Team May 19, 2026 1 min read 0 words
Base64 Encoding Explained: How It Works and When to Use It

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that converts binary data into a string of printable ASCII characters. It uses a set of 64 characters - A-Z, a-z, 0-9, +, and / - plus = for padding.

The primary purpose of Base64 is to safely transmit binary data through channels that only support text, such as email (MIME), HTML, JSON, and URLs.

How Base64 Works

The algorithm is straightforward:

  1. Take the input bytes
  2. Group them into blocks of 3 bytes (24 bits)
  3. Split each 24-bit block into 4 groups of 6 bits
  4. Map each 6-bit group to one of the 64 characters in the Base64 alphabet
  5. If the input isn't a multiple of 3 bytes, pad with =

Step-by-Step Example

Encoding the string "Hi":

StepData
ASCII bytesH = 72, i = 105
Binary01001000 01101001
Pad to 24 bits01001000 01101001 00000000
Split into 6-bit groups010010 000110 100100 000000
Base64 index18, 6, 36, 0
Base64 charsS, G, k, A
Add paddingSGk=

So "Hi" encodes to "SGk=".

Common Use Cases

Data URIs in HTML/CSS

Embed small images directly in HTML or CSS:

<img src="data:image/png;base64,iVBORw0KGgoAAAA..." />

API Authentication

HTTP Basic Authentication sends username:password as a Base64 string in the Authorization header:

Authorization: Basic dXNlcjpwYXNzd29yZA==

Email Attachments (MIME)

Email protocols like SMTP only handle 7-bit ASCII. Binary attachments (images, PDFs) are Base64-encoded before transmission.

JWT Tokens

JSON Web Tokens use Base64url encoding (a URL-safe variant) for the header and payload segments.

Base64 Is NOT Encryption

A critical misconception: Base64 is encoding, not encryption. It provides zero security - anyone can decode a Base64 string instantly. Never use Base64 to protect sensitive data. Use proper encryption (AES, RSA) instead.

Base64 Size Overhead

Base64 increases data size by approximately 33%. Every 3 input bytes become 4 output characters. For large files, this overhead matters - which is why Base64 data URIs are typically used only for small assets (icons, fonts under 10KB).

Base64url Variant

Standard Base64 uses + and /, which have special meaning in URLs. The Base64url variant replaces:

  • +-
  • /_
  • = padding → omitted

This variant is used in JWTs, URL parameters, and filenames.

Try It Yourself

Use our Base64 Encoder & Decoder to encode and decode text instantly - entirely in your browser with no server-side processing.

Share this article