RFC 4648

Base64 Encoder & Decoder

Encode text to Base64 or decode Base64 strings back to plain text. Supports Unicode and URL-safe Base64. Everything runs in your browser — no data is sent anywhere.

Mode
Output

How to use the Base64 tool

Three steps to encode or decode any text or Base64 string.

01

Select Mode

Click Encode to convert plain text into Base64, or Decode to convert a Base64 string back to readable text.

02

Paste Input

Type or paste your input into the text area. The result appears instantly — no button press needed. Unicode is fully supported.

03

Copy Output

Click the Copy button in the output footer. The output switches to green to confirm the copy was successful.

Code examples

Base64 encoding in JavaScript, Python, PHP, Go, and Bash.

// Encode plain text to Base64 (handles Unicode)
function encodeBase64(str) {
  return btoa(unescape(encodeURIComponent(str)));
}

// Decode Base64 back to plain text (handles Unicode)
function decodeBase64(b64) {
  return decodeURIComponent(escape(atob(b64)));
}

// URL-safe Base64 encode
function encodeUrlSafe(str) {
  return encodeBase64(str)
    .replace(/\+/g, '-')
    .replace(/\//g, '_');
}

// Usage
console.log(encodeBase64('Hello, World!')); // SGVsbG8sIFdvcmxkIQ==
console.log(decodeBase64('SGVsbG8sIFdvcmxkIQ==')); // Hello, World!
console.log(encodeBase64('Unicode: \u00e9\u00e0\u00fc')); // VW5pY29kZTogw6nDoMO8
import base64

# Encode bytes to Base64
data = b"Hello, World!"
encoded = base64.b64encode(data)
print(encoded)           # b'SGVsbG8sIFdvcmxkIQ=='
print(encoded.decode())  # SGVsbG8sIFdvcmxkIQ==

# Encode a string (encode to bytes first)
text = "Unicode: éàü"
encoded_str = base64.b64encode(text.encode('utf-8')).decode()
print(encoded_str)       # VW5pY29kZTogw6nDoMO8

# Decode Base64 back to string
decoded = base64.b64decode("SGVsbG8sIFdvcmxkIQ==").decode('utf-8')
print(decoded)           # Hello, World!

# URL-safe Base64
url_encoded = base64.urlsafe_b64encode(data).decode()
url_decoded = base64.urlsafe_b64decode(url_encoded)
print(url_decoded)       # b'Hello, World!'
// Encode a string to Base64
$text    = 'Hello, World!';
$encoded = base64_encode($text);
echo $encoded; // SGVsbG8sIFdvcmxkIQ==

// Decode Base64 back to a string
$decoded = base64_decode($encoded);
echo $decoded; // Hello, World!

// URL-safe Base64 (RFC 4648 §5)
function base64url_encode($data) {
    return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
    return base64_decode(strtr($data, '-_', '+/'));
}

// Validate Base64 before decoding
function is_base64($s) {
    return (bool) preg_match('/^[A-Za-z0-9+\/]*={0,2}$/', $s);
}
package main

import (
    "encoding/base64"
    "fmt"
)

func main() {
    text := "Hello, World!"
    data := []byte(text)

    // Standard Base64 encode
    encoded := base64.StdEncoding.EncodeToString(data)
    fmt.Println(encoded) // SGVsbG8sIFdvcmxkIQ==

    // Standard Base64 decode
    decoded, err := base64.StdEncoding.DecodeString(encoded)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }
    fmt.Println(string(decoded)) // Hello, World!

    // URL-safe Base64 (no padding)
    urlEncoded := base64.URLEncoding.EncodeToString(data)
    fmt.Println(urlEncoded) // SGVsbG8sIFdvcmxkIQ==

    // Raw URL-safe (no padding characters)
    rawUrlEncoded := base64.RawURLEncoding.EncodeToString(data)
    fmt.Println(rawUrlEncoded) // SGVsbG8sIFdvcmxkIQ
}
# Encode a string to Base64
echo -n "Hello, World!" | base64
# Output: SGVsbG8sIFdvcmxkIQ==

# Decode Base64 back to text
echo "SGVsbG8sIFdvcmxkIQ==" | base64 --decode
# Output: Hello, World!

# Encode a file to Base64
base64 image.png > image.b64

# Decode a Base64 file back to binary
base64 --decode image.b64 > image_restored.png

# URL-safe Base64 (replace + and / characters)
echo -n "Hello, World!" | base64 | tr '+/' '-_'
# Output: SGVsbG8sIFdvcmxkIQ==

# Encode without newline wrapping (macOS: -b 0, Linux: -w 0)
echo -n "Hello" | base64 -w 0

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using only 64 printable ASCII characters: A–Z, a–z, 0–9, +, and /. Every 3 bytes of binary data are converted to 4 Base64 characters, resulting in an output that is approximately 33% larger than the original.

The encoding is defined in RFC 4648 and is widely used across the web and networking protocols because many text-based systems cannot handle arbitrary binary data reliably.

Common uses of Base64

Remember: Base64 is encoding, not encryption. It is trivially reversible and provides no security. Never use it to protect sensitive data — use proper encryption algorithms instead.

Frequently asked questions

Everything you need to know about Base64 encoding and decoding.

What is Base64 encoding?
Base64 is a binary-to-text encoding scheme that converts binary data into a set of 64 printable ASCII characters. It is defined in RFC 4648 and is used wherever binary data must be transmitted or stored as text — such as in email, JWT tokens, and data URIs. Every 3 bytes of input produce 4 characters of output.
Is Base64 encryption?
No. Base64 is encoding, not encryption. It uses no key, provides no confidentiality, and can be decoded by anyone instantly. It only converts the representation of data — from binary to text. If you need to protect sensitive data, use a proper encryption algorithm like AES-256 or RSA.
What is URL-safe Base64?
Standard Base64 uses + and / characters, which have special meaning in URLs (+ means space; / is a path separator). URL-safe Base64 (RFC 4648 §5) replaces + with - and / with _, making the encoded string safe to include directly in URLs and filenames without percent-encoding. It is commonly used in JWT tokens and OAuth flows.
How do I encode Base64 in JavaScript?
The browser provides btoa() (binary to ASCII) and atob() (ASCII to binary). However, they do not handle Unicode directly. Use the wrapper pattern: btoa(unescape(encodeURIComponent(str))) to encode and decodeURIComponent(escape(atob(b64))) to decode. In Node.js, use Buffer.from(str).toString('base64') and Buffer.from(b64, 'base64').toString('utf8').
Why does Base64 output end with == ?
Base64 converts every 3 bytes into 4 characters. If the input is not divisible by 3, padding = signs are appended to make the output length a multiple of 4. One = means the last group had 2 bytes; two = signs (==) means it had only 1 byte. Padding ensures the encoded string can always be cleanly split into 4-character chunks during decoding.
Is my data safe when using this tool?
Yes, completely. All encoding and decoding is performed entirely in your browser using JavaScript's built-in btoa() and atob() functions. No data is transmitted to any server. Your input never leaves your device and is not logged or stored anywhere.

More developer tools

Free, browser-based tools for everyday developer tasks.

🕐

Epoch Converter

Convert Unix timestamps to readable dates and back.

Try it →
{}

JSON Formatter

Prettify, validate, and minify JSON instantly.

Try it →
🔗

URL Encoder

Encode and decode URL components and query strings.

Try it →
🔐

Password Generator

Generate strong, random passwords with custom rules.

Try it →
&

HTML Entities

Encode and decode HTML special characters and entities.

Try it →