Base64 Encoder and Decoder Guide โ€” How It Works with Examples

ToolsOfIndia.com Team ยท October 2026 ยท 6 min read

Base64 is one of those encoding schemes every developer encounters but few truly understand. You see it in data URIs, API tokens, email attachments, and JWT headers. Knowing how it works helps you debug issues and use it correctly. This guide explains what Base64 is, how it works, and how to use our free Base64 encoder and Base64 decoder tools.

What Is Base64?

Base64 is an encoding scheme that converts binary data into a text representation using 64 printable ASCII characters: Aโ€“Z, aโ€“z, 0โ€“9, +, and /. The = character is used for padding at the end.

The reason Base64 exists is simple: many protocols and formats (email, JSON, HTML, URLs) are designed for text, not binary. If you try to send raw binary data through a text channel, certain bytes can get corrupted or misinterpreted. Base64 solves this by converting any binary data into safe ASCII text.

How Base64 Encoding Works

Base64 processes data in groups of 3 bytes (24 bits) and splits them into 4 groups of 6 bits. Each 6-bit value maps to one of the 64 characters in the Base64 alphabet:

Original bytes:  01001000 01101001  (2 bytes = 16 bits)
Padded to 24 bits: 01001000 01101001 00000000
Split into 6-bit:  010010 000110 100100 000000
Base64 chars:     S       G       k       A  (=)

This is why Base64 output is about 33% larger than the input โ€” 3 bytes become 4 characters.

Base64 Encoding Examples

Encoding Text

Here is how the text "Hello, India!" encodes to Base64:

Input:  Hello, India!
Output: SGVsbG8sIEluZGlhIQ==

The == at the end is padding, which appears when the input length is not a multiple of 3 bytes.

Encoding in JavaScript

// Encode
const encoded = btoa("Hello, India!");
console.log(encoded); // SGVsbG8sIEluZGlhIQ==

// Decode
const decoded = atob("SGVsbG8sIEluZGlhIQ==");
console.log(decoded); // Hello, India!

Encoding in Python

import base64

# Encode
encoded = base64.b64encode(b"Hello, India!").decode()
print(encoded)  # SGVsbG8sIEluZGlhIQ==

# Decode
decoded = base64.b64decode("SGVsbG8sIEluZGlhIQ==").decode()
print(decoded)  # Hello, India!

Common Use Cases for Base64

Base64 vs. Base64url

Standard Base64 uses + and /, which are not URL-safe. Base64url replaces them with - and _, and omits padding. This variant is used in JWTs and other URL contexts:

Standard Base64: SGVsbG8+SW5kaWE/==
Base64url:        SGVsbG8-SW5kaWE_

Important: Base64 Is Not Encryption

A common misconception is that Base64 provides security. It does not. Base64 is a reversible encoding โ€” anyone can decode it with no key. Never use Base64 to protect sensitive data. For actual security, use encryption algorithms like AES with a proper key.

When Not to Use Base64

Conclusion

Base64 is an essential encoding scheme for transmitting binary data through text channels. Understanding how it works helps you use it correctly in APIs, email, and web development. Use our free Base64 encoder and Base64 decoder tools to quickly encode or decode any data in your browser.

Try Our Free Tools

Use our free online calculators and tools for all your needs.

Browse All 213+ Tools โ†’