DevTools

Base64 Encode & Decode Online

Convert text to Base64 encoding and vice versa. Useful for encoding binary data as ASCII text.

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme that represents arbitrary byte sequences as printable ASCII characters. It works by taking every three bytes of input (24 bits), splitting them into four 6-bit groups, and mapping each group to one of 64 characters: A-Z, a-z, 0-9, +, and /. If the input length is not a multiple of three, the output is padded with one or two = signs.

The encoding exists because many transport layers — email (SMTP/MIME), JSON, XML, HTML attributes, HTTP headers — are designed for 7-bit ASCII text. Embedding raw binary data (images, PDFs, cryptographic keys) directly into those channels would corrupt the payload. Base64 bridges that gap: it inflates size by about 33% but guarantees the output is plain ASCII that survives any text-based transport without mangling.

You encounter Base64 everywhere in web development: data URIs for inline images (data:image/png;base64,...), the payload section of JWTs, Basic authentication headers (Authorization: Basic dXNlcjpwYXNz), email attachments (MIME), and binary fields in JSON APIs.

Base64 Variants: Standard, URL-Safe, and MIME

The standard Base64 alphabet (RFC 4648 Section 4) uses + and / as its 62nd and 63rd characters. This is fine inside a JSON string or an email body, but problematic inside URLs and filenames, where + and / have special meanings. URL-safe Base64 (RFC 4648 Section 5) replaces them with - and _, and often omits the trailing = padding. JWT tokens use URL-safe encoding without padding by default.

MIME Base64 (RFC 2045) inserts a line break every 76 characters to keep each line short enough for email relays that impose line-length limits. If you decode MIME-wrapped Base64 and get garbled output, strip the line breaks first — most decoders expect a single unbroken string.

This tool uses the standard alphabet by default. If your input contains - or _ instead of + and /, it is likely URL-safe encoded — the tool handles both transparently.

Common Pitfalls

Base64 encoding looks simple, but a few sharp edges trip up developers regularly.

UTF-8 and Multi-Byte Characters

The browser's built-in btoa() function only accepts Latin-1 characters (code points 0-255). Passing a string containing Chinese, Japanese, emoji, or any character above U+00FF throws an InvalidCharacterError. The fix is to encode the string to UTF-8 bytes first with TextEncoder, then convert each byte to a Latin-1 character before calling btoa(). This tool handles that conversion automatically — you can paste emoji, CJK text, or any valid Unicode and get correct Base64 output.

Line Breaks and Whitespace

Some Base64 producers wrap output at 76 characters (MIME) or 64 characters (PEM certificates). Most decoders silently strip whitespace, but not all of them — the browser's atob() rejects input containing newlines in strict mode. If you paste wrapped Base64 and get an error, the tool strips whitespace before decoding.

Base64 Is Not Encryption

Base64 is a reversible encoding, not a cipher. Anyone can decode a Base64 string in milliseconds. Never use Base64 to hide secrets — API keys, passwords, or personal data. If you only need an irreversible fingerprint (for integrity checks or deduplication), compute a Hash Generator digest instead. If you need confidentiality, encrypt the data first (AES-GCM is a sensible default) and then Base64-encode the ciphertext for transport.

How to Encode or Decode Base64

  1. 1
    Paste your input. Type or paste text in the left panel (to encode) or a Base64 string in the right panel (to decode). The direction is detected automatically based on which panel you type in.
  2. 2
    Read the result. The opposite panel updates instantly. UTF-8, emoji, and multi-byte characters are handled automatically.
  3. 3
    Copy the output. Click the copy button at the top of the output panel to put the result on your clipboard.
  4. 4
    Clear and start over. Hit the Clear button in either panel's toolbar to reset both sides.
Code Examples
JavaScript / Node.js
// Encode (handles UTF-8 correctly)
const bytes = new TextEncoder().encode("Hello 🌍");
const encoded = btoa(String.fromCharCode(...bytes));

// Decode
const binary = atob(encoded);
const decoded = new TextDecoder().decode(
  Uint8Array.from(binary, (c) => c.charCodeAt(0))
);
Python
import base64

# Encode
encoded = base64.b64encode("Hello 🌍".encode("utf-8")).decode()

# Decode
decoded = base64.b64decode(encoded).decode("utf-8")

# URL-safe variant
url_safe = base64.urlsafe_b64encode(b"binary data").decode()
Go
import "encoding/base64"

// Standard encoding
encoded := base64.StdEncoding.EncodeToString([]byte("Hello"))

// Decoding
decoded, _ := base64.StdEncoding.DecodeString(encoded)

// URL-safe variant (no padding)
urlSafe := base64.RawURLEncoding.EncodeToString([]byte("Hello"))
Bash
# Encode (no line wrapping)
echo -n "Hello" | base64 -w 0

# Decode
echo "SGVsbG8=" | base64 --decode

# macOS (BSD base64 has no -w flag)
echo -n "Hello" | base64
echo "SGVsbG8=" | base64 -D
Frequently Asked Questions

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that converts binary data into a set of 64 printable ASCII characters (A-Z, a-z, 0-9, +, /). It is commonly used to embed binary data in text formats like JSON, XML, HTML, and email.

How do I encode text to Base64?

Paste your text into the input field and select Encode. The Base64 output will appear instantly. You can then copy it with one click.

Does Base64 encoding keep my data private?

No. Base64 is an encoding, not encryption. Anyone can decode a Base64 string. If you need to protect sensitive data, use proper encryption before encoding.

Why is my Base64 string longer than the original?

Base64 encoding increases data size by approximately 33% because it represents every 3 bytes of input as 4 ASCII characters. This is a trade-off for safe text transport.

How do I convert Base64 to ASCII text?

Paste your Base64 string into the input field and select Decode. The tool converts it back to the original ASCII text instantly. For non-ASCII content like emoji or CJK characters, UTF-8 decoding is applied automatically.

Can I convert binary data to Base64?

Base64 was designed to encode binary data as printable text. This tool handles text-to-Base64 conversion directly. For raw binary files, you can read the file as a data URI or use command-line tools like base64 (Linux/Mac) or certutil (Windows).

Related Developer Tools