Base64 Encode & Decode Online | URL-Safe & Hex Converter
Encoding How It Works
What Is Base64?
Base64 is a binary-to-text encoding scheme defined in RFC 4648. It represents binary data using 64 printable ASCII characters (A–Z, a–z, 0–9, +, /). Every 3 bytes of input becomes 4 Base64 characters, increasing data size by approximately 33%. It is widely used for transporting binary data in text-based protocols like email (MIME), JSON, and URLs.
When to Use Base64
- Data URIs — embed images or fonts directly in HTML/CSS as Base64-encoded data URLs
- JWT tokens — URL-safe Base64 encodes the header, payload, and signature of JSON Web Tokens
- Email attachments — MIME uses Base64 to encode binary attachments for transport over SMTP
- API data transport — encode binary data (keys, certificates, images) as text for JSON/XML payloads
- Configuration files — store small binary blobs (icons, fonts) as Base64 in config or source code
Base64 Variant Comparison
| Variant | Characters | Padding | Best for |
|---|---|---|---|
| Standard | A-Z, a-z, 0-9, +, / | = (required) | Email, data URIs, general-purpose |
| URL-safe | A-Z, a-z, 0-9, -, _ | Optional (often omitted) | JWT tokens, OAuth, web URLs |
Standards Compliance
- RFC 4648 — The Base16, Base32, and Base64 Data Encodings
- RFC 2045 — MIME (Multipurpose Internet Mail Extensions) — Base64 for email
- RFC 7515 — JSON Web Signature (JWS) — uses URL-safe Base64
- Web Crypto API — uses Base64URL for key export/import operations
Last updated:
Code Examples
JavaScript (Browser)
// Base64 encode/decode (UTF-8 safe)
const text = 'hello world 你好';
// Encode
const encoded = btoa(unescape(encodeURIComponent(text)));
console.log(encoded); // aGVsbG8gd29ybGQg5L2g5aW9
// Decode
const decoded = decodeURIComponent(escape(atob(encoded)));
console.log(decoded); // hello world 你好
// URL-safe variant
const urlSafe = encoded.replace(/+/g, '-').replace(///g, '_').replace(/=+$/, '');
console.log(urlSafe); Python
import base64
text = 'hello world 你好'.encode('utf-8')
# Standard encoding
encoded = base64.b64encode(text).decode()
print(f'Standard: {encoded}')
# URL-safe encoding
url_safe = base64.urlsafe_b64encode(text).decode().rstrip('=')
print(f'URL-safe: {url_safe}')
# Decode
decoded = base64.b64decode(encoded).decode('utf-8')
print(f'Decoded: {decoded}') Go
package main
import (
"encoding/base64"
"fmt"
)
func main() {
data := []byte("hello world")
// Standard encoding
encoded := base64.StdEncoding.EncodeToString(data)
fmt.Println("Standard:", encoded)
// URL-safe encoding
urlSafe := base64.URLEncoding.EncodeToString(data)
fmt.Println("URL-safe:", urlSafe)
// Decode
decoded, _ := base64.StdEncoding.DecodeString(encoded)
fmt.Println("Decoded:", string(decoded))
} Rust
use base64::{Engine as _, engine::general_purpose};
fn main() {
let data = b"hello world";
// Standard encoding
let encoded = general_purpose::STANDARD.encode(data);
println!("Standard: {}", encoded);
// URL-safe encoding
let url_safe = general_purpose::URL_SAFE_NO_PAD.encode(data);
println!("URL-safe: {}", url_safe);
// Decode
let decoded = general_purpose::STANDARD.decode(&encoded).unwrap();
println!("Decoded: {}", String::from_utf8(decoded).unwrap());
} Node.js
// Node.js — Base64 encode/decode
const text = 'hello world';
// Encode
const encoded = Buffer.from(text, 'utf-8').toString('base64');
console.log('Encoded:', encoded);
// Decode
const decoded = Buffer.from(encoded, 'base64').toString('utf-8');
console.log('Decoded:', decoded);
// URL-safe variant
const urlSafe = encoded.replace(/+/g, '-').replace(///g, '_').replace(/=+$/, '');
console.log('URL-safe:', urlSafe); Common Pitfalls
Security Notes
Disclaimer
This tool is provided for educational and development purposes. Base64 is an encoding scheme, not encryption — never use it to protect sensitive data. All conversion occurs entirely in your browser.
Further Reading
- RFC 4648 — The Base16, Base32, and Base64 Data Encodings
- MDN — Base64 Encoding and Decoding
- RFC 7515 — JSON Web Signature (JWS)
- Wikipedia — Base64
Related Concepts
- Hex/Text Converter — Hexadecimal Encoding
- Encoding vs Encryption — Understanding the Difference
- JWT Tokens — Base64URL in Practice
- Base64 Encode/Decode
Related Tools
Need to convert hex to text? Try the Hex/Text Converter. For generating unique identifiers, see the UUID Generator. You can also encode classical ciphers with the Classical Ciphers Toolkit.
Frequently Asked Questions
Is Base64 encryption?
No. Base64 is an encoding scheme, not encryption. It provides no security — anyone can decode it. It is used for data transport, not data protection. Never use Base64 to store sensitive data.
Why does Base64 output look longer than the input?
Base64 encoding increases data size by approximately 33%. Every 3 bytes of input becomes 4 characters of output. This overhead is the trade-off for representing binary data as safe, printable text.
What is URL-safe Base64?
URL-safe Base64 (RFC 4648 §5) replaces + and / with - and _ to make the output safe for URLs and filenames. It also omits padding (=) characters. This variant is used in JWT tokens, OAuth, and other web protocols.
What is the difference between standard and URL-safe Base64?
Standard Base64 uses + and / characters, while URL-safe uses - and _ instead. Both encode the same bytes, but URL-safe is safe for URLs, filenames, and query parameters without additional encoding. Standard is used for email, data URIs, and general purposes.
Can I decode Base64 to hex?
Yes. Switch to decode mode and select "Hex" as the output format. The tool will decode the Base64 and display the raw bytes as a hexadecimal string, which is useful for inspecting binary data.
Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.
More in Encoding
UUID Generator
Generate UUID v4 (random) and v7 (time-ordered) online. Configurable format, batch generation (1-1000), validation, timestamp extraction.
Hex/Text Cipher Converter
Convert between hex, plain text, binary, and Uint8Array online. Configurable hex output with separator and case options.
Classical Ciphers Toolkit
Encode, decode, and break classical ciphers online: Caesar, Vigenère, Atbash, Rail Fence. Frequency analysis, chi-squared brute force, auto key recovery.