Base64 Encoder & Decoder — Free Online Tool
Free online Base64 encoder & decoder. Convert text or files to Base64 and back. Supports standard and URL-safe encoding. Everything runs in your browser — your data never leaves your device.
What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into a string of 64 printable ASCII characters. It is defined in RFC 4648 and is used whenever binary data needs to travel through text-only channels — like email (MIME), JSON APIs, HTML data URIs, or HTTP headers.
The encoding alphabet consists of A–Z, a–z, 0–9, +, and / (plus = for padding). The URL-safe variant (Base64URL) replaces + with - and / with _ to avoid conflicts in URLs and filenames.
Base64 is not encryption. It is a reversible encoding that anyone can decode. Never use Base64 to protect sensitive data like passwords or API keys.
How Base64 Encoding Works
Base64 converts every 3 bytes (24 bits) of input into 4 characters (6 bits each) from the Base64 alphabet. Here is the classic example — encoding the word "Man":
Step 1 — Convert each character to its ASCII byte value:
77
97
110
Step 2 — Convert to binary (24 bits total):
01001101 01100001 01101110
Step 3 — Split into 6-bit groups and map to Base64 characters:
| 6-bit Group | Binary | Decimal | Base64 Char |
|---|---|---|---|
| 1st | 010011 | 19 | T |
| 2nd | 010110 | 22 | W |
| 3rd | 000101 | 5 | F |
| 4th | 101110 | 46 | u |
Result: "Man" → "TWFu"
What about padding? If the input length is not a multiple of 3 bytes, Base64 pads the output with = characters. 1 missing byte → ==, 2 missing bytes → =. For example: "Ma" → "TWE=", "M" → "TQ==".
Base64 Alphabet Table
The standard Base64 character set maps values 0–63 to these 64 characters:
| Value | Char | Value | Char | Value | Char | Value | Char |
|---|---|---|---|---|---|---|---|
| 0 | A | 16 | Q | 32 | g | 48 | w |
| 1 | B | 17 | R | 33 | h | 49 | x |
| 2 | C | 18 | S | 34 | i | 50 | y |
| 3 | D | 19 | T | 35 | j | 51 | z |
| 4 | E | 20 | U | 36 | k | 52 | 0 |
| 5 | F | 21 | V | 37 | l | 53 | 1 |
| 6 | G | 22 | W | 38 | m | 54 | 2 |
| 7 | H | 23 | X | 39 | n | 55 | 3 |
| 8 | I | 24 | Y | 40 | o | 56 | 4 |
| 9 | J | 25 | Z | 41 | p | 57 | 5 |
| 10 | K | 26 | a | 42 | q | 58 | 6 |
| 11 | L | 27 | b | 43 | r | 59 | 7 |
| 12 | M | 28 | c | 44 | s | 60 | 8 |
| 13 | N | 29 | d | 45 | t | 61 | 9 |
| 14 | O | 30 | e | 46 | u | 62 | + |
| 15 | P | 31 | f | 47 | v | 63 | / |
URL-safe variant: value 62 maps to - (instead of +) and value 63 maps to _ (instead of /). Padding = is omitted. Use this when embedding Base64 in URLs, filenames, or JWT tokens.
Common Uses of Base64
Base64 encoding appears everywhere in modern web development:
Data URIs in HTML/CSS
Embed images inline: data:image/png;base64,...
Email Attachments (MIME)
Binary files encoded for text-only SMTP transport
JSON & XML Payloads
Store binary data (images, files) in text-based formats
HTTP Basic Auth
Authorization: Basic dXNlcjpwYXNz
JWT Tokens
Header and payload are Base64URL-encoded
Source Maps & Fonts
Inline fonts and source maps in CSS/JS bundles
Base64 Encoding vs Encryption
A common misconception is that Base64 provides security. It does not:
| Feature | Base64 Encoding | Encryption (e.g. AES) |
|---|---|---|
| Purpose | Data transport (binary → text) | Data protection (confidentiality) |
| Reversible? | Yes, by anyone | Only with the key |
| Key required? | No | Yes (secret key) |
| Size overhead | ~33% larger | Varies (block padding) |
| Use for passwords? | Never | Use hashing instead |
How to Encode & Decode Base64 in Code
Quick reference for Base64 encoding in the most popular languages:
JavaScript
// Encode
const encoded = btoa("Hello, World!");
// "SGVsbG8sIFdvcmxkIQ=="
// Decode
const decoded = atob("SGVsbG8sIFdvcmxkIQ==");
// "Hello, World!"
// Unicode-safe encode (handles emojis, CJK, etc.)
const utf8 = new TextEncoder().encode("Hello");
const b64 = btoa(String.fromCharCode(...utf8));
Python
import base64
# Encode
encoded = base64.b64encode(b"Hello, World!").decode()
# "SGVsbG8sIFdvcmxkIQ=="
# Decode
decoded = base64.b64decode("SGVsbG8sIFdvcmxkIQ==").decode()
# "Hello, World!"
# URL-safe
url_safe = base64.urlsafe_b64encode(b"data").decode()
Command Line (Linux / macOS)
# Encode
echo -n "Hello, World!" | base64
# SGVsbG8sIFdvcmxkIQ==
# Decode
echo "SGVsbG8sIFdvcmxkIQ==" | base64 --decode
# Hello, World!
# Encode a file
base64 image.png > image.b64
Frequently Asked Questions
What is Base64 encoding?
Base64 is a binary-to-text encoding scheme that represents binary data using 64 printable ASCII characters (A–Z, a–z, 0–9, +, /). It is commonly used to safely transmit binary data over text-based systems like email (MIME), JSON APIs, and HTTP headers. The standard is defined in RFC 4648.
Is Base64 encoding the same as encryption?
No. Base64 is a reversible encoding, not encryption. Anyone can decode a Base64 string without needing a key. Never use Base64 to protect sensitive data like passwords, API keys, or personal information. Use proper encryption (like AES) or hashing (like bcrypt) instead.
Why does Base64 increase file size by 33%?
Base64 converts every 3 bytes of input into 4 ASCII characters. Each character uses 8 bits to represent only 6 bits of actual data. This means the output is always approximately 33% larger than the input (4/3 ratio). Padding characters (=) can add a few extra bytes.
What is URL-safe Base64?
Standard Base64 uses + and / characters, which have special meaning in URLs. URL-safe Base64 (defined in RFC 4648 Section 5) replaces them with - and _, and omits padding. It is used in JWT tokens, URL query parameters, and filenames.
What does the = sign mean in Base64?
The = character is padding. Base64 processes input in groups of 3 bytes. If the input length is not a multiple of 3, the output is padded: 1 byte remaining adds ==, 2 bytes remaining adds =. This ensures the output length is always a multiple of 4.
How do I encode or decode Base64 in JavaScript?
Use btoa() to encode a string to Base64 and atob() to decode. For Unicode text (emojis, CJK characters), first encode to UTF-8 using TextEncoder, then convert the bytes to a binary string before calling btoa(). See the MDN documentation for details.
Can I convert an image to Base64?
Yes. Click the Upload button in the encoder and select an image file. The tool converts it to a Base64 string that you can embed directly in HTML or CSS as a data URI (e.g., data:image/png;base64,...). This eliminates the need for separate HTTP requests but increases the HTML file size by ~33%.