Base64 Encoder & Decoder
Convert images, files, and text to and from Base64 instantly.
100% client-side — nothing is uploaded to any server.
What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into a set of 64 printable ASCII characters. It is not encryption or compression — it is a way to safely represent binary data (images, files, audio) using only letters, digits, and two special characters.
The name comes from the fact that it uses 64 possible characters (A-Z, a-z, 0-9, +, /) to represent data. Each Base64 character represents exactly 6 bits of the original binary data, which is why the encoded output is always about 33% larger than the original input.
Base64 is defined in RFC 4648 and has become the standard way to embed binary data in text-based formats like JSON, XML, HTML, email messages, and URL query strings.
The Problem Base64 Solves
Many systems — email protocols, JSON APIs, HTML documents, URL query strings — are designed to handle text, not raw binary. Binary data contains bytes that can be interpreted as control characters, line breaks, or in some encodings, byte values that don't exist.
For example, the byte value 0x00 (null) would terminate a C string. The byte 0x0A (newline) embedded in a JSON value would break the format. SMTP (email) was historically designed for 7-bit ASCII, making any byte with the 8th bit set unreliably transmitted.
Base64 solves this by mapping every 3 bytes of binary data into 4 safe, printable ASCII characters that survive any text-based transport without corruption. When you send an image attachment via email, embed a PNG in an HTML data URI, or transmit a file through a JSON API, Base64 is working behind the scenes.
How Base64 Encoding Works — Algorithm Walkthrough
The encoding algorithm processes the input data in groups of 3 bytes at a time. Each 3-byte group (24 bits) is split into four 6-bit values, and each 6-bit value is mapped to a character in the Base64 alphabet.
Algorithm Overview:
- Take the input data as a stream of bytes
- Group bytes into chunks of 3 (24 bits total)
- Split each 24-bit chunk into four 6-bit values
- Map each 6-bit value to the corresponding Base64 character
- If the last chunk has fewer than 3 bytes, apply padding with
=
Step-by-Step Example: Encoding “Cat”
Let's trace through the encoding of the word “Cat” (3 bytes, one complete chunk) to see exactly how this works.
| Step 1 | Take the ASCII values: C = 67, a = 97, t = 116 |
| Step 2 | Convert to binary (8 bits each): 01000011 01100001 01110100 |
| Step 3 | Join into one 24-bit stream: 010000110110000101110100 |
| Step 4 | Split into four 6-bit groups: |
010000 = 16110110 = 54000101 = 5110100 = 52 | |
| Step 5 | Map to Base64 alphabet (A=0, B=1 ... Z=25, a=26 ... 0=52, + = 62, / = 63): |
16 → Q54 → 25 → F52 → 0 | |
| Result | Q2F0 ← Base64 for “Cat” |
The 3-byte input “Cat” became 4 Base64 characters: Q2F0. This 4:3 ratio means Base64 output is always ~33% larger than the raw binary input.
The Base64 Character Table
Each 6-bit value (0–63) maps to exactly one character. Here is the complete mapping:
0–25A–Z26–51a–z52–610–962+63/(pad)=The = sign is not part of the 64-character alphabet. It is used solely as padding at the end of the encoded string when the input is not evenly divisible by 3 bytes.
Base64 Padding Explained
What happens when your input is not a perfect multiple of 3 bytes? The standard requires the output length to be a multiple of 4 characters, so padding with = fills the gap.
| Input | Bytes | Base64 Output | Padding |
|---|---|---|---|
| “C” | 1 byte | Qw== | == (2 pads) |
| “Ca” | 2 bytes | Q2E= | = (1 pad) |
| “Cat” | 3 bytes (perfect) | Q2F0 | none |
The rule is simple:
- 1 remaining byte → add
==(2 padding characters) - 2 remaining bytes → add
=(1 padding character) - 0 remaining bytes (exact multiple of 3) → no padding needed
Many URL-safe Base64 implementations (like JWT) omit padding entirely since the decoder can infer the original length from the encoded length alone. When padding is removed, you can always restore it: add trailing = until the length is a multiple of 4.
Base64 Variants: Standard vs URL-Safe vs MIME
Not all Base64 is the same. Different contexts use slightly different alphabets and formatting rules:
Standard Base64
Uses A-Z, a-z, 0-9, +, / with = padding. The default encoding for most programming languages and tools.
SGVsbG8rV29ybGQvQmFzZTY0URL-Safe Base64 (Base64URL)
Replaces + with - and / with _. Often omits padding. Used in JWT tokens, URL query parameters, and filename-safe contexts.
SGVsbG8tV29ybGRfQmFzZTY0MIME Base64
Standard Base64 with line breaks every 76 characters. Used in email attachments (Content-Transfer-Encoding: base64).
VGhpcyBpcyBhIGxvbmcgc3RyaW5nIHRoYXQgd291bGQgYmUgd3JhcHBlZCBhdCA3NiBjaGFy
YWN0ZXJzIHBlciBsaW5lIGZvciBlbWFpbCBjb21wYXRpYmlsaXR5Lg==Where You Encounter Base64 Every Day
Base64 is everywhere in modern computing. Here are the most common places you'll encounter it — often without realizing:
- HTML Data URIs: Embedded images, fonts, and SVGs in CSS and HTML. Example:
<img src="data:image/png;base64,iVBORw..." /> - Email Attachments: Every image, PDF, or ZIP you send via email is Base64-encoded by your mail client before transit. The MIME standard requires it.
- JWT Tokens: JSON Web Tokens use Base64URL to encode header and payload parts. The familiar
eyJhbGciOi...pattern is Base64URL. - HTTP Basic Auth: The
Authorization: Basic ...header carries Base64-encoded credentials:btoa("user:pass") - JSON APIs: When you need to transmit binary file content through a text-only JSON REST or GraphQL endpoint, Base64 strings are the go-to format.
- OAuth 2.0 & OpenID Connect: Client credentials, assertion payloads, and state parameters often use Base64URL encoding for safe URL transit.
- Kubernetes Secrets: Values in Kubernetes Secret manifests are Base64-encoded:
echo -n "mypassword" | base64 - CSS background-images: Small icons and patterns are often inlined as Base64 data URIs to save HTTP requests.
Quick Reference: Encode and Decode in Any Language
Every modern programming environment includes built-in Base64 support. Here are the one-liners:
// JavaScript (Browser)
const encoded = btoa("Hello"); // "SGVsbG8="
const decoded = atob("SGVsbG8="); // "Hello"
// Python
import base64
encoded = base64.b64encode(b"Hello").decode() # SGVsbG8=
decoded = base64.b64decode(encoded) # b"Hello"
// Java
String encoded = Base64.getEncoder().encodeToString("Hello".getBytes());
String decoded = new String(Base64.getDecoder().decode(encoded));
// C#
string encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello"));
string decoded = Encoding.UTF8.GetString(Convert.FromBase64String(encoded));
// Go
import "encoding/base64"
encoded := base64.StdEncoding.EncodeToString([]byte("Hello"))
decoded, _ := base64.StdEncoding.DecodeString(encoded)
// Terminal
echo -n "Hello" | base64 # SGVsbG8=
echo -n "SGVsbG8=" | base64 -d # HelloCommon Base64 Misconceptions
“Base64 is encryption”
False. Base64 provides zero security. Anyone can decode it instantly. It is an encoding format, not a cryptographic algorithm. Use AES, ChaCha20, or RSA for actual encryption.
“Base64 compresses data”
Base64 makes data about 33% larger — never smaller. Each 3 bytes of input becomes 4 characters of output. If you want compression, use gzip or brotli first, then Base64-encode the compressed result.
“All Base64 looks the same”
There are at least 3 common variants: standard (+/ with = padding), URL-safe (-_ without padding), and MIME (with 76-char line breaks). Using the wrong variant when decoding will produce errors or corrupted output.
Start Converting Right Now
All our tools run entirely in your browser. Paste a string, upload a file, or type into any tool above — your data is processed locally on your device and never leaves it. Use the tabs at the top to switch between text encoding, image-to-Base64 conversion, and Base64-to-file decoding. Browse the complete collection of 21 tools below for every Base64 task you might need.
All Tools
Browse our complete collection of Base64 tools — all running entirely in your browser.
Core Tools
Conversion Tools
Media Tools
Utility Tools
Base64 Validator
Validate and analyze Base64 strings for correctness
Base64 Compare
Compare two Base64 strings and find differences
Base64 Normalizer
Normalize Base64 strings to various standard formats
Base64 Repair
Fix malformed or corrupted Base64 strings
HMAC Generator
Generate HMAC signatures and JWT tokens
Niche Tools
Gzip Test
Test compression ratios of text and Base64 with gzip
Base64 Detector
Identify which Base64 variant a string uses
Uuencode Decoder
Decode legacy uuencoded data back to original files
ASCII Table
Full ASCII character reference (0–255) with hex and binary
Base64 Characters
Complete Base64 alphabet table with index and binary values
Basic Auth Decoder
Decode/encode HTTP Basic Authentication headers
Frequently Asked Questions
Search below or browse through our most commonly asked questions.