Base64 Encode

Input text
0 characters

Free online Base64 encode/decode tool supporting UTF-8/ASCII/ISO-8859-1 with Standard, URL-Safe, and MIME variants. Live size overhead, RFC 2045 compliant MIME line wrapping, all processing happens locally in your browser.

Related

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme based on 64 printable ASCII characters, first defined in RFC 2045 (the MIME standard). Base64 converts every 3 bytes (24 bits) into 4 Base64 characters (A-Z, a-z, 0-9, +, /), so binary data can be transmitted safely through text-only systems such as HTTP headers, JSON payloads, XML documents, or URL query parameters.

**Base64 is not encryption.** It only converts data formats, and anyone can decode it back to the original. If you need to protect sensitive data, use a real encryption scheme such as AES. Common Base64 use cases include HTTP Basic Authentication (`Authorization: Basic dXNlcjpwYXNz`), the header and payload segments of JWT tokens (Base64URL format), Data URIs (`data:image/png;base64,...`), and MIME encoding for email attachments.

**URL-Safe Base64** (RFC 4648 §5) replaces the standard Base64 characters +/ with -_ and typically omits the = padding. This makes the encoded result safe to use in URLs, file paths, or JSON fields. JWT tokens, OAuth PKCE code_verifier values, and AWS Signature V4 all rely on URL-Safe Base64 encoding.

**MIME line wrapping** is the RFC 2045 rule that no line should exceed 76 characters. When Base64 content is used in email or other contexts that require wrapped lines, the MIME variant automatically inserts a newline character (`\n`) every 76 characters. This is the standard format for transmitting email attachments.

The tool uses the browser's native **btoa / atob** APIs, combined with UTF-8-safe handling logic, to make sure that multibyte characters such as Chinese text and Japanese emoji are encoded correctly. All computation runs locally — your data is never sent to any server. Open the Network tab in your browser's developer tools and you can verify that there are zero outbound requests.

Use Cases

  • JWT debugging: decode the header and payload segments of a JWT (Base64URL format) to inspect the token's claims
  • Basic Auth: encode a username:password pair into an HTTP Basic authentication credential
  • OAuth development: generate the code_verifier for PKCE flows or verify an incoming code_challenge
  • API debugging: encode JSON payloads or decode Base64 fields returned by an API
  • Data URI image embedding: convert small icons into data:image/...;base64,... format to embed directly in CSS or HTML
  • Email attachment encoding: encode binary email attachments in the MIME Base64 format

How to Use

  1. Choose a mode: click Encode or Decode to switch the processing direction
  2. Pick a variant: Standard, URL-Safe (for JWT / OAuth), or MIME (76-char email-format line wrapping)
  3. Enter content: paste text or a Base64 string and the tool processes it in real time
  4. Review stats: the bottom panel shows the character counts and the size overhead (about +33% for encoding)
  5. Copy the result: one click copies the Base64 string or the decoded text to your clipboard

Features

  • One-click Encode / Decode toggle: switch freely between encoding and decoding modes, with the output becoming the next input for circular processing
  • Three charset support: UTF-8 (Chinese / Japanese / emoji), ASCII, and ISO-8859-1 for professional-grade multi-scenario coverage
  • Three output variants: Standard, URL-Safe (for JWT / OAuth / PKCE), and MIME (RFC 2045 compliant 76-character line wrapping)
  • Real-time size statistics: live input / output character counts and overhead ratio (Base64 grows the payload by ~33%)
  • Friendly error messages: clear, specific errors when characters fall outside the valid range instead of a generic failure
  • Draggable divider on desktop: adjust the left / right editor ratio to focus on the current task
  • Independent mobile tabs: phones and tablets get separate tabs for the input and output panels, keeping the workflow smooth

Code Examples

Base64 Encoding in JavaScript (UTF-8 Support)

// Encode (supports UTF-8)
function b64Encode(str) {
  return btoa(unescape(encodeURIComponent(str)));
}

// Decode (supports UTF-8)
function b64Decode(str) {
  return decodeURIComponent(escape(atob(str)));
}

// URL-Safe encode (for JWT / OAuth)
function b64UrlEncode(str) {
  return btoa(unescape(encodeURIComponent(str)))
    .replace(/\+/g, '-')
    .replace(/\//g, '_')
    .replace(/=+$/, '');
}

console.log(b64Encode('Hello 世界')); // SGVsbG8g5LiW55WM
console.log(b64Decode('SGVsbG8g5LiW55WM')); // Hello 世界

Base64 Encoding in Python

import base64

# Standard encode (UTF-8)
encoded = base64.b64encode('Hello 世界'.encode('utf-8'))
print(encoded.decode())  # SGVsbG8g5LiW55WM

# Standard decode
decoded = base64.b64decode(encoded).decode('utf-8')
print(decoded)  # Hello 世界

# URL-Safe encode (for JWT / OAuth)
url_safe = base64.urlsafe_b64encode('Hello 世界'.encode('utf-8'))
print(url_safe.decode())  # SGVsbG8g5LiW55WM (no padding — strip manually)

# Strip padding (JWT convention)
url_safe_no_pad = url_safe.decode().rstrip('=')
print(url_safe_no_pad)

Base64 Encoding in Java

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Base64Example {
    public static void main(String[] args) {
        String text = "Hello 世界";

        // Standard encode
        String encoded = Base64.getEncoder()
            .encodeToString(text.getBytes(StandardCharsets.UTF_8));
        System.out.println(encoded); // SGVsbG8g5LiW55WM

        // Standard decode
        String decoded = new String(
            Base64.getDecoder().decode(encoded), StandardCharsets.UTF_8);
        System.out.println(decoded); // Hello 世界

        // URL-Safe encode (for JWT / URL)
        String urlSafe = Base64.getUrlEncoder().withoutPadding()
            .encodeToString(text.getBytes(StandardCharsets.UTF_8));
        System.out.println(urlSafe);

        // MIME encode (76-char line wrapping)
        String mime = Base64.getMimeEncoder()
            .encodeToString(text.getBytes(StandardCharsets.UTF_8));
    }
}

FAQ

Is Base64 encoding the same as encryption?

No. Base64 is just a reversible transformation that turns text into another representation anyone can decode back to the original. If you are dealing with sensitive data (passwords, tokens), use a real encryption scheme such as AES. Base64 is only meant for data format conversion, so binary data can be safely transmitted through text-only systems.

AES Encrypt / Decrypt Tool

How much larger does the data get after Base64 encoding?

Base64 encoding increases the original data size by about 33%. This is because every 3 bytes (24 bits) are encoded as 4 Base64 characters. For example, 100 bytes of text becomes roughly 133 bytes after encoding. The bottom of the tool shows the live overhead ratio so you can quickly evaluate the resulting size. Example: `Hello` → `SGVsbG8=` (size +33%).

Base64 Stats Tool

What is the difference between Standard, URL-Safe, and MIME?

Standard is the canonical Base64 alphabet using A-Z, a-z, 0-9, +, /. URL-Safe replaces +/ with -_, making the result safe for URL parameters and JWT tokens. MIME inserts a line break every 76 characters, following the RFC 2045 email transmission standard, which is the format used for email attachments and multi-line text.

URL-Safe Base64MIME Base64

How do I decode a JWT header or payload?

JWT uses Base64URL (the URL-Safe variant). Switch the tool to URL-Safe mode, then paste the first segment (header) or the second segment (payload) to decode it. Note that the third segment of a JWT is a signature and should not be decoded to verify the token.

JWT Tool

What is Base64 padding?

The length of a Base64-encoded string must always be a multiple of 4. When the input length is not a multiple of 3 bytes, the output is padded with = characters. The URL-Safe variant does not use padding. The tool handles padding automatically and strips trailing = characters when decoding.

Base64 Padding Tool

Why do btoa and atob in JavaScript not support Chinese characters?

btoa and atob are built-in browser APIs that operate on the Latin-1 (ISO-8859-1) character set, where every character takes 1 byte. Chinese characters occupy 3 bytes in UTF-8, so passing them in directly throws an error. The fix is to first use encodeURIComponent to turn the Chinese text into a UTF-8 byte sequence in %xx form, then use unescape to convert it to a Latin-1 string, and finally call btoa to encode it.

What is the Data URI Scheme and how do I embed images with Base64?

A Data URI is a URI format that embeds data directly inside the URL itself, with the syntax: `data:[<mediatype>][;base64],<data>`. For example, `data:image/png;base64,iVBORw0KGgo...`. It is commonly used to inline small icons, CSS background images, and other assets to cut down on HTTP requests. However, because Base64 increases the size by about 33%, it is best suited to small files — large files should still be served via a normal URL.

Data URI ToolBase64 to Image

Glossary

RFC 4648
The IETF official standard for Base16 / Base32 / Base64 encodings, defining the Standard and URL-Safe Base64 alphabets along with rules for padding, line breaks, and non-alphabet characters. It is the de facto Base64 standard today and supersedes the earlier RFC 3548.URL-Safe Base64 ToolBase64 Padding Tool
RFC 2045 (MIME)
The Multipurpose Internet Mail Extensions (MIME) standard, which first introduced Base64 as a content transfer encoding for email. It requires that Base64 output use lines of no more than 76 characters separated by CRLF, giving rise to the MIME Base64 variant.MIME Base64 Tool
Base64URL (URL-Safe Base64)
The URL-safe variant defined in RFC 4648 §5. It replaces the + with - and / with _ from the standard Base64 alphabet, and usually omits the = padding. It is widely used for JWT tokens, OAuth PKCE values, URL parameters, and file names.URL-Safe Base64 ToolJWT Tool
MIME Base64
A Base64 variant that complies with RFC 2045, inserting a CRLF line break every 76 characters. It is mainly used for email attachment transmission, because older SMTP protocols impose a limit on the length of a single line.MIME Base64 Tool
Padding
Base64-encoded output length must be a multiple of 4. When the input byte count is not a multiple of 3, the end is padded with = characters. Standard Base64 uses padding, while Base64URL usually omits it.Base64 Padding Tool
Base64 Alphabet
The set of 64 characters used in Base64 encoding. The standard Base64 alphabet is A-Z (26), a-z (26), 0-9 (10), +, and /, totaling 64 characters, plus the = padding character.Base64 Encode
btoa / atob
Native browser APIs for Base64 encoding and decoding. btoa (binary to ASCII) encodes, atob (ASCII to binary) decodes. Note that these APIs only support the Latin-1 character set, so handling Chinese text requires pairing them with UTF-8 transcoding.Base64 Encode
Data URI Scheme
A URI format that allows small files to be embedded directly inside a URL, written as data:[<mediatype>][;base64],<data>. It is commonly used to inline small icons and CSS background images to reduce HTTP requests.Data URI ToolBase64 to Image
HTTP Basic Authentication
An HTTP authentication scheme that joins the username and password with a colon, Base64-encodes the result, and sends it in the Authorization request header. The format is: Authorization: Basic <base64(username:password)>.Auth Header Builder
Base64 Overhead
The percentage by which Base64 encoding grows the data. Every 3 bytes (24 bits) becomes 4 Base64 characters, so the payload grows by about 33% (4/3 ≈ 1.333). The overhead can be slightly higher when padding is included.

Base64 Variant Comparison

FeatureStandardURL-SafeMIME
Special chars+ /- _+ /
Padding (=)UsedOmittedUsed
Line breaksNoneNoneEvery 76 chars
StandardRFC 4648 §4RFC 4648 §5RFC 2045
Use casesData URI, generalJWT, URL, filenamesEmail, SMTP

Base Encoding Family Comparison

EncodingCharsCharsetOverheadUse Case
Base16 (Hex)160-9, A-F100%Debugging, hash display
Base3232A-Z, 2-7 (uppercase, no ambiguity)60%DNS, TOTP secrets, QR codes
Base5858Excludes ambiguous 0/O/I/l38%Bitcoin addresses, crypto
Base6262A-Z, a-z, 0-934%URL shorteners, ID encoding
Base6464A-Z, a-z, 0-9, +, /33%Data URI, MIME, JWT (URL-Safe variant)

Authoritative References