Base64 Encode & Decode Online | URL-Safe & Hex Converter

Encoding
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.

How It Works

Base64 is NOT encryption. It is an encoding scheme that provides zero security — anyone can decode it. Never use Base64 to protect sensitive data. For actual confidentiality, use AES-256-GCM encryption.

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

VariantCharactersPaddingBest for
StandardA-Z, a-z, 0-9, +, /= (required)Email, data URIs, general-purpose
URL-safeA-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

Confusing Base64 with encryption. Base64 is an encoding scheme, not encryption. It provides zero security — anyone can decode it. For confidentiality, use AES-256-GCM.
Ignoring UTF-8 encoding. JavaScript's btoa() only handles Latin1 characters. For Unicode text, use TextEncoder first, then encode the bytes to Base64.
Using standard Base64 in URLs. Standard Base64 uses + and / characters which have special meaning in URLs. Use URL-safe Base64 (with - and _) for JWT tokens and web URLs.
Not handling padding correctly. Standard Base64 requires = padding to make the output length a multiple of 4. URL-safe Base64 often omits padding — add it back before decoding if needed.
Base64 increases data size by ~33%. Every 3 bytes becomes 4 characters. For large binary data, consider compression (gzip) before encoding,, or use binary transfer protocols.

Security Notes

Base64 provides no confidentiality. It is a representation format, not a security mechanism. Sensitive data must be encrypted before Base64 encoding.
URL-safe variant for web protocols. JWT, OAuth, and other web standards use URL-safe Base64 to avoid encoding issues in URLs and query parameters.
Validate input before decoding. Malformed Base64 can cause errors or unexpected behavior. Always validate that input contains only valid Base64 characters before decoding.
Use for data URIs. Base64 enables embedding images and fonts directly in HTML/CSS, reducing HTTP requests at the cost of ~33% larger payload size.

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

Related Concepts

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