Updated 2026-10-09•6 min read•100% Free & Browser-Based
How Base64 Encoding and Decoding Works: Complete Guide & Examples
Base64 is one of the most widely used data encodings on the web. It allows binary data—like images, PDFs, encryption keys, and hashes—to travel safely over text-only protocols like HTTP, email (MIME), and JSON payloads without data corruption.
Interactive Tool
Base64 Encoder
Encode text into Base64.
Step-by-Step Instructions
- 1Take 3 input bytes (24 bits total) from your binary or text data.
- 2Split the 24 bits into 4 groups of 6 bits each.
- 3Map each 6-bit integer (ranging from 0 to 63) to the Base64 alphabet table (A-Z, a-z, 0-9, +, /).
- 4If the input byte count is not divisible by 3, pad the end with one or two = characters.
Why Do We Need Base64 Encoding?
Historical network protocols (like early SMTP and ASCII terminals) were designed to handle only 7-bit ASCII printable characters. When transmitting raw 8-bit binary files, control characters (null bytes, carriage returns, bell sounds) would cause protocol parsers to corrupt or terminate data streams.
Base64 solves this by mapping any binary stream into an universally safe 64-character set that is guaranteed to traverse any network protocol without escaping or corruption.
The Mathematics of 24-Bit to 6-Bit Conversion
The Base64 algorithm takes chunks of 3 bytes (3 × 8 bits = 24 bits) and reorganizes them into 4 characters (4 × 6 bits = 24 bits). Because 2^6 = 64, each 6-bit chunk maps directly to one of 64 characters:
- A–Z (indices 0–25)
- a–z (indices 26–51)
- 0–9 (indices 52–61)
- + (index 62)
- / (index 63)
This conversion results in a 33% increase in data size (every 3 bytes expand to 4 bytes).
TEXT
Text Input: "Man"
ASCII Hex: 0x4D, 0x61, 0x6E
Binary (24b): 01001101 01100001 01101110
6-bit Chunks: 010011 | 010110 | 000101 | 101110
Decimal: 19 | 22 | 5 | 46
Base64 Char: T | W | F | u
Output: "TWFu"Understanding Base64 Padding (= and ==)
What happens when your input does not contain a multiple of 3 bytes?
- If 1 byte remains (8 bits): The algorithm pads 4 zero bits to form two 6-bit chunks, followed by two = padding characters (e.g. "M" -> "TQ==").
- If 2 bytes remain (16 bits): The algorithm pads 2 zero bits to form three 6-bit chunks, followed by one = padding character (e.g. "Ma" -> "TWE=").
- If 3 bytes remain (24 bits): No padding is required.
Standard Base64 vs Base64URL
In web environments, standard Base64 characters + and / have special meanings in URLs (+ represents space, / represents path separators). Standard Base64 can also break URL routing when padding = appears.
Base64URL modifies standard Base64 by:
1. Replacing + with -
2. Replacing / with _
3. Omitting trailing = padding characters
This is the format used in JSON Web Tokens (JWT) and URL query parameters.
Frequently asked questions
No. Base64 is an encoding format, not encryption. Anyone can instantly decode Base64 back to original text without a key or password.
Because 3 bytes of raw binary expand into 4 ASCII characters, resulting in an exact 33.3% size overhead.
Related Browser Tools
Try these free, local browser utilities mentioned in this guide.
Developer
Base64 Decoder
Decode Base64-encoded strings back to plain text and UTF-8.
Developer
URL Encoder
Percent-encode text and parameters for safe use in URLs and APIs.
Developer
URL Decoder
Decode percent-encoded URL strings and query parameters to plain text.
Developer
JWT Decoder
Decode a JSON Web Token header and payload.