What Is Base64 Encoding? How It Works, When to Use It, and Examples
Updated May 5, 2026 · 10 min read
Written by Muhammad Abdullah Rauf · Founder, EverydayTools.pro
Quick answer: Base64 converts binary data into ASCII text so it can safely pass through text-based systems (JSON, email, URLs). It is not encryption — it provides zero security and is trivially reversible.
Try it yourself:
Free Base64 Encoder / Decoder →The Core Problem Base64 Solves
Early internet protocols — email (SMTP), HTML, XML, JSON — were designed for text. Binary data (images, audio, executable files) contains bytes with values from 0 to 255, many of which are not printable characters and can be misinterpreted by text-based systems. Bytes like 0x00 (null), 0x0D (carriage return), and 0x0A (newline) have special meanings in text protocols and cause corruption when embedded directly.
Base64 solves this by encoding every 3 bytes of binary data into exactly 4 printable characters. The output only uses 64 safe characters — A–Z, a–z, 0–9, +, / — that are safe in any ASCII-based system.
How Base64 Encoding Works
Base64 works in groups of 3 bytes (24 bits). It splits those 24 bits into four 6-bit groups, then looks each 6-bit value up in the Base64 alphabet table (where 0 = A, 1 = B, ... 63 = /):
// Encoding "Man" → "TWFu"
M → ASCII 77 → binary: 01001101
a → ASCII 97 → binary: 01100001
n → ASCII 110 → binary: 01101110
// Concatenate: 010011010110000101101110
// Split into 6-bit groups:
010011 → 19 → T
010110 → 22 → W
000101 → 5 → F
101110 → 46 → u
Result: "TWFu"
The Base64 Alphabet
| Value | Char | Value | Char | Value | Char |
|---|---|---|---|---|---|
| 0 | A | 26 | a | 52 | 0 |
| 1 | B | 27 | b | 53 | 1 |
| 2 | C | 28 | c | 54 | 2 |
| ... | ... | ... | ... | ... | ... |
| 25 | Z | 51 | z | 61 | 9 |
| 62 | + | 63 | / | pad | = |
Base64 Encoding Examples
| Input text | Hex bytes | Base64 output |
|---|---|---|
| Hello | 72 65 6C 6C 6F | SGVsbG8= |
| Man | 4D 61 6E | TWFu |
| Hi! | 48 69 21 | SGkh |
| 2026 | 32 30 32 36 | MjAyNg== |
Where You Encounter Base64
Data URIs in HTML/CSS
src="data:image/png;base64,iVBORw0KGgo..."Embeds images directly in HTML without a separate file request. Common for small icons and favicons.
JWT Tokens
eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiYWxpY2UifQ...JWT header and payload are URL-safe Base64 encoded (without padding). Decode any JWT at /jwt-decoder.
API Authentication Headers
Authorization: Basic dXNlcjpwYXNzHTTP Basic Auth encodes "username:password" as Base64. Note: this is NOT secure over HTTP — use HTTPS.
Email Attachments (MIME)
Content-Transfer-Encoding: base64SMTP email encodes binary attachments as Base64 to travel through text-only email relays.
Embedded JSON Blobs
{ "icon": "iVBORw0KGgoAAAANSUhEUg..." }APIs sometimes return images or small files as Base64 strings inside JSON responses.
Base64 Variants
| Variant | Characters 62–63 | Padding | Used in |
|---|---|---|---|
| Standard (RFC 4648) | + / | = (yes) | MIME email, general use |
| URL-safe (RFC 4648 §5) | - _ | = (optional) | JWTs, URLs, filenames |
| Base64 without padding | + / | None | Some APIs, OAuth tokens |
When NOT to Use Base64
- For security: Base64 is reversible in milliseconds. Never use it to protect passwords or sensitive data. Use bcrypt/Argon2 for passwords and AES for sensitive data.
- For large file transfers: Base64 increases file size by ~33%. Transfer large files as binary over HTTP/2 instead.
- For performance-critical images: Large images as data URIs increase HTML size and block rendering. Use separate image files with proper caching instead.
Base64 in Code
# Encode btoa('Hello World') // → 'SGVsbG8gV29ybGQ=' # Decode atob('SGVsbG8gV29ybGQ=') // → 'Hello World'
# Encode Buffer.from('Hello').toString('base64') // → 'SGVsbG8=' # Decode Buffer.from('SGVsbG8=', 'base64').toString() // → 'Hello'
# Encode import base64; base64.b64encode(b'Hello').decode() # → 'SGVsbG8=' # Decode base64.b64decode('SGVsbG8=').decode() # → 'Hello'
# Encode echo -n 'Hello' | base64 # → SGVsbG8= # Decode echo 'SGVsbG8=' | base64 -d # → Hello
Need to encode or decode Base64 without writing code?
Use the free browser-based tool — paste any text or upload a file, and get the Base64 output instantly. No server upload. Handles text, files, and images.
Open Base64 Encoder/Decoder →Frequently Asked Questions
What is Base64 encoding?
Base64 is an encoding scheme that converts binary data (bytes) into a string of 64 printable ASCII characters. It maps every 3 bytes of input to 4 characters from the Base64 alphabet (A–Z, a–z, 0–9, +, /). The result is about 33% larger than the original binary data but safe to transmit through any text-based system.
Is Base64 the same as encryption?
No. Base64 is encoding, not encryption. Encoding transforms data into a different representation for compatibility — it is fully reversible and provides zero security. Anyone can decode Base64 instantly. Never use Base64 to hide sensitive data like passwords or API keys. Use proper encryption (AES, RSA) for security purposes.
Why does Base64 end with = or ==?
Base64 works in groups of 3 bytes. If the input length is not divisible by 3, padding characters (=) are added to make it so. One = means 1 byte of padding was added; == means 2 bytes of padding. This padding ensures the decoder knows the exact original length. Some Base64 variants (like URL-safe Base64) omit padding.
What is URL-safe Base64?
Standard Base64 uses + and / which have special meaning in URLs. URL-safe Base64 replaces + with - and / with _ to produce output that can be used in URLs and filenames without percent-encoding. It is used in JWT tokens and many modern APIs.
When should I use Base64?
Use Base64 when you need to embed binary data (images, files, audio) in a text-based format like JSON, XML, HTML, or email. Common scenarios: data URIs in CSS/HTML, JWT tokens, embedding images in API responses, email attachments (MIME), and OAuth tokens. Do NOT use Base64 to increase file transfer efficiency — it adds 33% overhead.
How do I decode a Base64 string?
Use our free Base64 encoder/decoder tool to decode any Base64 string instantly in your browser. In JavaScript: atob('SGVsbG8=') returns 'Hello'. In Python: import base64; base64.b64decode('SGVsbG8=').decode() returns 'Hello'. In command line: echo 'SGVsbG8=' | base64 -d.