HeoLab
ToolsBlogAboutContact
HeoLab

Free developer tools with AI enhancement. Built for developers who ship.

Tools

  • JSON Formatter
  • JWT Decoder
  • Base64 Encoder
  • Timestamp Converter
  • Regex Tester
  • All Tools →

Resources

  • Blog
  • What is JSON?
  • JWT Deep Dive
  • Base64 Explained

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 HeoLab. All rights reserved.

Tools work in your browser. Zero data retention.

HomeBlogWhat is Base64 Encoding and How Does It Work?
Table of Contents▾
  • Table of Contents
  • Why Base64 Exists
  • The Base64 Alphabet
  • How Encoding Works
  • Padding
  • Base64 vs Base64URL
  • When to Use It
encoding#base64#encoding#fundamentals

What is Base64 Encoding and How Does It Work?

A clear explanation of Base64 encoding — what it is, why it exists, and how the encoding algorithm works step by step.

Trong Ngo
February 22, 2026
2 min read

Table of Contents

  • Why Base64 Exists
  • The Base64 Alphabet
  • How Encoding Works
  • Padding
  • Base64 vs Base64URL
  • When to Use It

Why Base64 Exists

Binary data (images, files, keys) can contain any byte value (0–255). Many protocols — email (SMTP), HTTP headers, JSON — are designed for text and can't safely carry arbitrary binary.

Base64 solves this by encoding binary into a subset of ASCII characters that are safe to transmit anywhere.

The Base64 Alphabet

Base64 uses 64 characters: A–Z (26), a–z (26), 0–9 (10), + and / (2). Each character represents 6 bits of data. Three bytes (24 bits) → four Base64 characters.

How Encoding Works

Take the string Man:

  1. ASCII bytes: M=77, a=97, n=110
  2. Binary: 01001101 01100001 01101110
  3. Split into 6-bit groups: 010011 010110 000101 101110
  4. Map to alphabet: indices 19, 22, 5, 46 → T, W, F, u → TWFu
btoa("Man")   // "TWFu"
atob("TWFu")  // "Man"

Padding

If the input isn't divisible by 3 bytes, = padding is added:

  • 1 leftover byte → 2 Base64 chars + ==
  • 2 leftover bytes → 3 Base64 chars + =

Base64 vs Base64URL

Standard Base64 uses + and / which are special in URLs. Base64URL replaces them:

StandardBase64URL
+-
/_

JWTs use Base64URL encoding.

When to Use It

  • Embedding images in HTML/CSS (data URIs)
  • Encoding binary in JSON APIs
  • Email attachments (MIME)

Note: Base64 is encoding, not encryption. Anyone can decode it.

Try the Base64 Encoder/Decoder to convert data instantly.

Try These Tools

Base64 Encoder / Decoder

Encode text and binary data to Base64 or decode Base64 strings. Supports URL-safe variant.

Related Articles

Unix Timestamps: A Complete Developer's Guide

2 min read

Base64 is Not Encryption: Security Misconceptions Explained

1 min read

Base64 vs Hex Encoding: Key Differences

2 min read

Back to Blog

Table of Contents

  • Table of Contents
  • Why Base64 Exists
  • The Base64 Alphabet
  • How Encoding Works
  • Padding
  • Base64 vs Base64URL
  • When to Use It

Related Articles

Unix Timestamps: A Complete Developer's Guide

2 min read

Base64 is Not Encryption: Security Misconceptions Explained

1 min read

Base64 vs Hex Encoding: Key Differences

2 min read