Base64 Encoder & Decoder

Processed entirely in your browser. Your data is never sent to our servers.

What is Base64 Encoding?

Base64 is a binary-to-text encoding scheme defined in RFC 4648. It represents binary data using a set of 64 ASCII characters: A-Z, a-z, 0-9, +, and /, with = used for padding. Base64 is one of the most widely used encoding formats on the web, found in emails, data URIs, APIs, and configuration files.

The primary purpose of Base64 is to allow binary data to be safely transmitted through text-based systems that may not handle raw binary correctly — such as email (MIME), JSON payloads, HTML attributes, and URL parameters.

How Base64 Encoding Works

Base64 encoding works by dividing the input data into groups of 3 bytes (24 bits). Each group is then split into four 6-bit values, and each 6-bit value is mapped to one of the 64 characters in the Base64 alphabet. If the input length is not a multiple of 3, the output is padded with one or two = characters.

Step-by-Step Example: Encoding "Man"

Here is how the string Man is converted to its Base64 representation TWFu:

StepMan
ASCII value7797110
Binary (8 bits)010011010110000101101110

The 24 bits (010011010110000101101110) are regrouped into four 6-bit values:

6-bit group010011010110000101101110
Decimal value1922546
Base64 characterTWFu

Result: ManTWFu. When the input length is not a multiple of 3, padding (=) is added: MaTWE= and MTQ==.

The Base64 Character Set

ValueCharValueCharValueCharValueChar
0A16Q32g48w
1B17R33h49x
2C18S34i50y
3D19T35j51z
4E20U36k520
5F21V37l531
6G22W38m542
7H23X39n553
8I24Y40o564
9J25Z41p575
10K26a42q586
11L27b43r597
12M28c44s608
13N29d45t619
14O30e46u62+
15P31f47v63/

Base64URL Variant

The Base64URL encoding (also defined in RFC 4648, Section 5) is a URL-safe variant that replaces + with - and / with _. It also typically omits the = padding characters. Base64URL is safe for use in URLs and filenames without percent-encoding.

Base64URL is used in JSON Web Tokens (JWT), URL parameters, and filenames where standard Base64 characters would need to be percent-encoded. If you are working with JWT tokens, try our JWT Decoder & Encoder tool.

Common Uses of Base64

Base64 in Programming Languages

JavaScript

JavaScript provides built-in btoa() and atob() functions for Base64 encoding and decoding. For UTF-8 strings, use TextEncoder and TextDecoder to handle multi-byte characters correctly.

// Encode
const encoded = btoa('Hello, World!');  // "SGVsbG8sIFdvcmxkIQ=="

// Decode
const decoded = atob('SGVsbG8sIFdvcmxkIQ==');  // "Hello, World!"

// UTF-8 safe encode (handles emoji, CJK, etc.)
const utf8Encode = btoa(String.fromCharCode(
  ...new TextEncoder().encode('Hello ')
));

// UTF-8 safe decode
const bytes = Uint8Array.from(atob(encoded), c => c.charCodeAt(0));
const utf8Decode = new TextDecoder().decode(bytes);

Python

Python's base64 module provides b64encode() and b64decode(), plus urlsafe_b64encode() for URL-safe Base64.

import base64

# Encode
encoded = base64.b64encode(b'Hello, World!')  # b'SGVsbG8sIFdvcmxkIQ=='

# Decode
decoded = base64.b64decode(b'SGVsbG8sIFdvcmxkIQ==')  # b'Hello, World!'

# URL-safe variant (replaces + with - and / with _)
url_safe = base64.urlsafe_b64encode(b'Hello, World!')

# Encode a string (must encode to bytes first)
text = 'Hello'
encoded_str = base64.b64encode(text.encode('utf-8')).decode('ascii')

Java

Java 8+ provides java.util.Base64 with getEncoder(), getDecoder(), getUrlEncoder(), and getMimeEncoder().

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

// Encode
String encoded = Base64.getEncoder()
    .encodeToString("Hello, World!".getBytes(StandardCharsets.UTF_8));
// "SGVsbG8sIFdvcmxkIQ=="

// Decode
byte[] decoded = Base64.getDecoder().decode("SGVsbG8sIFdvcmxkIQ==");
String text = new String(decoded, StandardCharsets.UTF_8);

// URL-safe encoding
String urlSafe = Base64.getUrlEncoder().withoutPadding()
    .encodeToString("Hello, World!".getBytes(StandardCharsets.UTF_8));

// MIME encoding (76-char line wrap)
String mime = Base64.getMimeEncoder()
    .encodeToString(largeByteArray);

PHP

PHP provides base64_encode() and base64_decode() as built-in functions.

// Encode
$encoded = base64_encode('Hello, World!');  // "SGVsbG8sIFdvcmxkIQ=="

// Decode
$decoded = base64_decode('SGVsbG8sIFdvcmxkIQ==');  // "Hello, World!"

// Strict mode (returns false on invalid characters)
$result = base64_decode($input, true);
if ($result === false) {
    echo "Invalid Base64 input";
}

// Encode a file
$fileData = file_get_contents('image.png');
$base64File = base64_encode($fileData);

Character Encoding Support

This tool supports 29 character encodings for Base64 encoding and decoding, allowing you to work with text in virtually any Western, Cyrillic, Greek, Arabic, Hebrew, Thai, or Vietnamese script. Select the appropriate encoding from the dropdown to ensure your text is correctly converted to and from Base64.

Supported encoding families include UTF-8, ASCII, ISO-8859 (Latin-1 through Latin-10), Windows code pages (1250–1258, 874), KOI8-R, KOI8-U, IBM-866, and Macintosh Roman. All encoding and decoding is performed entirely in your browser — no data is sent to any server.

Base64 vs Encryption

Base64 is not encryption. It is a reversible encoding that provides no security whatsoever. Anyone can decode Base64 data without any key or password. Base64 is designed for data transport and compatibility, not for data protection. If you need to protect sensitive data, use actual encryption algorithms like AES or RSA.

Frequently Asked Questions

What is Base64 encoding?

Base64 is a binary-to-text encoding scheme that represents binary data using 64 ASCII characters (A-Z, a-z, 0-9, +, /). It is commonly used to embed binary data in text-based formats like JSON, XML, HTML, and email. Base64 increases the data size by approximately 33%.

Is it safe to decode Base64 online?

It depends on the tool. This Base64 decoder processes everything entirely in your browser using client-side JavaScript. Your data is never sent to any server. However, you should avoid pasting sensitive data into tools that send data to a backend. Always check whether a tool is client-side only before pasting sensitive data.

What is the difference between Base64 and Base64URL?

Standard Base64 uses + and / as the 63rd and 64th characters, with = for padding. Base64URL (defined in RFC 4648) replaces + with - and / with _, and typically omits padding. Base64URL is safe for use in URLs and filenames without percent-encoding.

Is Base64 encryption?

No. Base64 is an encoding, not encryption. It does not provide any security — anyone can decode Base64 data without a key. It is designed for data transport, not data protection. Never use Base64 to hide sensitive information.

Why does Base64 make data larger?

Base64 encodes every 3 bytes of binary data into 4 ASCII characters. This results in a 33% size increase (4/3 ratio). The overhead is the trade-off for being able to safely transmit binary data through text-only channels.

What is a data URI?

A data URI (data URL) embeds Base64-encoded data directly in HTML or CSS using the format data:[mediatype];base64,[data]. This allows small files like images or fonts to be included inline without separate HTTP requests.