How to encode and decode Base64 online
jsonsql.dev encodes and decodes Base64 instantly in your browser. No data is sent to any server — your text stays on your machine.
Choose a mode — select Encode to convert text to Base64, or Decode to convert Base64 back to text.
Enter your input — paste text or a Base64 string into the left panel. You can also drag and drop a file to encode it as a Base64 data URI.
Copy the result — the converted output appears instantly in the right panel. Click Copy to copy it to your clipboard.
Example
Encoding plain text to Base64:
Input: Hello, World! 🌍
Output: SGVsbG8sIFdvcmxkISDwn4yNDecoding Base64 back to text:
Input: SGVsbG8sIFdvcmxkISDwn4yN
Output: Hello, World! 🌍URL-safe variant (replaces + with - and / with _):
Standard: U29tZSBkYXRhIHdpdGggKyBhbmQgLw==
URL-safe: U29tZSBkYXRhIHdpdGggKyBhbmQgLw (no padding)Features
- Encode text to Base64 and decode Base64 to text with full UTF-8 support
- URL-safe Base64 mode — replaces
+/with-_for use in URLs and filenames - Optional padding removal — strip trailing
=characters - Auto-detect mode — automatically suggests Decode when the input looks like Base64
- File encoding — drag and drop or select any file to convert it to a Base64 data URI
- Real-time size statistics — see input and output byte sizes and expansion ratio
- Dark and light theme support
- Works offline — no internet needed after the page loads
What is Base64 encoding
Base64 encoding converts binary data into a text-safe format using 64 ASCII characters. It increases data size by approximately 33% but ensures safe transmission through text-only protocols like email and JSON.
The 64 characters in the Base64 alphabet are: uppercase letters A–Z (26), lowercase letters a–z (26), digits 0–9 (10), and the symbols + and / (2). A 65th character, =, is used as padding to align the output length to a multiple of 4.
Why Base64 exists
Many protocols and file formats — including email (SMTP), JSON, XML, and HTML — are designed to carry text, not raw binary. Embedding binary data directly can corrupt the stream because certain byte values conflict with control characters or delimiters. Base64 solves this by re-encoding binary data using only printable ASCII characters that pass safely through any text channel.
How the encoding process works
Base64 reads the input 3 bytes (24 bits) at a time and splits them into four 6-bit groups. Each 6-bit group maps to one of the 64 characters in the alphabet. If the input length is not a multiple of 3, the output is padded with one or two = characters. This 3-byte-to-4-character mapping is why Base64 output is always approximately 33% larger than the original data.
Original (3 bytes): M a n
ASCII values: 77 97 110
Binary: 01001101 01100001 01101110
Split into 6 bits: 010011 010110 000101 101110
Base64 index: 19 22 5 46
Base64 character: T W F uSo the string "Man" encodes to "TWFu" — 3 bytes become 4 characters.
Base64 vs Base64URL
Base64URL replaces '+' with '-' and '/' with '_' to make the output URL-safe. JWT tokens use Base64URL encoding for this reason.
| Aspect | Standard Base64 (RFC 4648 §4) | Base64URL (RFC 4648 §5) |
|---|---|---|
| 62nd character | + | - |
| 63rd character | / | _ |
| Padding | Required (=) | Often omitted |
| Safe in URLs | No — + and / have special meaning | Yes |
| Safe in filenames | No — / is a path separator | Yes |
| Used by | Email MIME, PEM certificates, XML | JWT, OAuth tokens, URL query params |
On jsonsql.dev, enable the URL-safe checkbox to switch between the two variants. Combine it with No padding to produce the compact format used in JWT tokens.
Common Base64 use cases
Base64 appears across almost every layer of modern web development. Here are the most common scenarios:
Embedding images in HTML and CSS (data URIs)
Small images can be inlined directly into HTML or CSS using a data URI, eliminating an extra HTTP request:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..." />
/* CSS */
.icon { background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0...); }This technique is best for small icons and SVGs under 1–2 KB. Larger images are more efficient as separate files.
Encoding API credentials (HTTP Basic Auth)
HTTP Basic Authentication encodes the username and password as Base64:
Authorization: Basic dXNlcjpwYXNzd29yZA==
// dXNlcjpwYXNzd29yZA== = base64("user:password")Note: this is encoding, not encryption. Always use HTTPS when sending credentials.
Storing binary data in JSON
JSON has no binary type, so binary data like images, certificates, or encrypted blobs must be Base64-encoded to fit inside a JSON string:
{
"avatar": "iVBORw0KGgoAAAANSUhEUgAA...",
"certificate": "MIICIjANBgkqhkiG9w0BAQ..."
}Email attachments (MIME)
Email protocols transmit text only. Binary attachments (images, PDFs, ZIPs) are Base64-encoded in MIME parts so they survive transit through mail servers.
JWT token encoding
JSON Web Tokens encode the header and payload as Base64URL (without padding) so they can be safely included in HTTP headers and URLs:
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.signature
↑ header (Base64URL) ↑ payload (Base64URL)Use the JWT Decoder to inspect these tokens.
Base64 encoding in different languages
Most languages have built-in Base64 support. Here are quick examples:
JavaScript (browser)
// Encode
const encoded = btoa('Hello, World!') // "SGVsbG8sIFdvcmxkIQ=="
// Decode
const decoded = atob('SGVsbG8sIFdvcmxkIQ==') // "Hello, World!"
// For UTF-8 / emoji (btoa only handles Latin-1):
const utf8Encode = (str) =>
btoa(String.fromCharCode(...new TextEncoder().encode(str)))
const utf8Decode = (b64) =>
new TextDecoder().decode(Uint8Array.from(atob(b64), c => c.charCodeAt(0)))Node.js
// Encode
Buffer.from('Hello, World!').toString('base64') // "SGVsbG8sIFdvcmxkIQ=="
// Decode
Buffer.from('SGVsbG8sIFdvcmxkIQ==', 'base64').toString('utf-8') // "Hello, World!"
// URL-safe variant
Buffer.from('Hello, World!').toString('base64url') // "SGVsbG8sIFdvcmxkIQ"Python
import base64
# Encode
base64.b64encode(b'Hello, World!') # b'SGVsbG8sIFdvcmxkIQ=='
# Decode
base64.b64decode(b'SGVsbG8sIFdvcmxkIQ==') # b'Hello, World!'
# URL-safe
base64.urlsafe_b64encode(b'Hello, World!') # b'SGVsbG8sIFdvcmxkIQ=='Command line (Linux / macOS)
# Encode
echo -n 'Hello, World!' | base64 # SGVsbG8sIFdvcmxkIQ==
# Decode
echo 'SGVsbG8sIFdvcmxkIQ==' | base64 -d # Hello, World!
# Encode a file
base64 image.png > image.b64Base64 Encoder vs other tools
| Feature | jsonsql.dev | base64encode.org | base64 (CLI) |
|---|---|---|---|
| Browser-based | Yes | Yes | No (CLI) |
| Client-side only | Yes | No (server) | Yes (local) |
| UTF-8 support | Yes | Yes | Yes |
| URL-safe mode | Yes | No | Manual |
| File encoding | Yes (drag & drop) | Yes (upload) | Yes |
| Auto-detect mode | Yes | No | No |
| Dark mode | Yes | No | N/A |
| No install needed | Yes | Yes | Pre-installed on most OS |
Related tools
Frequently asked questions
What is the difference between Base64 and Base64URL?
Standard Base64 uses + and / as its 62nd and 63rd characters, which conflict with URL syntax. Base64URL (RFC 4648 §5) replaces them with - and _ and typically omits padding. JWT tokens, OAuth, and URL query parameters use Base64URL.
Is Base64 encryption?
No. Base64 is encoding, not encryption. It does not provide any security — anyone can decode a Base64 string without a key. If you need to protect data, use actual encryption (AES, RSA) and then optionally Base64-encode the encrypted output for safe transport.
How does Base64 handle UTF-8 and multibyte characters?
jsonsql.dev uses the TextEncoder API to convert Unicode text (including emoji, CJK characters, Arabic, Vietnamese diacritics, etc.) to UTF-8 bytes before Base64 encoding. The standard btoa() function only handles Latin-1, but this tool handles full Unicode correctly.
Why does Base64 make files bigger?
Base64 maps every 3 bytes of input to 4 ASCII characters, resulting in a 33% size increase. This overhead is the trade-off for representing binary data using only printable text characters. With line breaks added (as in MIME), the overhead can reach 36–37%.
Can I encode files to Base64 data URIs?
Yes. Drag and drop a file onto the input area or click "browse" to select one. The file is encoded as a Base64 data URI that you can embed in HTML, CSS, or JSON.