Base64 is a binary-to-text encoding algorithm that converts binary data into an ASCII string using 64 printable characters as defined in RFC 4648.
Base64 is a binary-to-text encoding scheme defined in RFC 4648 that translates arbitrary binary octets into a sequence of 64 printable ASCII characters. It is engineered to transmit binary data—such as image files, cryptographic signatures, or binary blobs—across legacy text-based transmission protocols like SMTP email, HTTP headers, XML, and JSON without risking data corruption or character set mangling.
You can encode and decode text or binary data directly in your browser using our Base64 Encoder & Decoder tool.
| Property | Standard Base64 | Base64URL (URL-Safe) |
|---|---|---|
| Standard Reference | RFC 4648 §4 | RFC 4648 §5 |
| Alphabet Length | 64 characters + padding (=) |
64 characters (often unpadded) |
| Index 62 Character | + (Plus sign) |
- (Minus / hyphen) |
| Index 63 Character | / (Slash) |
_ (Underscore) |
| Padding Character | = (Required for 3-byte alignment) |
Omitted or %3D |
| Safe for URL / Filenames? | No (+ and / collide with URL delimiters) |
Yes (No percent-encoding required) |
| Payload Expansion | +33.33% ($4 \text{ bytes per } 3 \text{ bytes}$) | +33.33% ($4 \text{ bytes per } 3 \text{ bytes}$) |
The Base64 algorithm maps binary data by grouping bits into 6-bit chunks (called sextets). Since $2^6 = 64$, each 6-bit chunk maps directly to one of 64 pre-defined ASCII characters:
Alphabet Index:
0–25: A–Z
26–51: a–z
52–61: 0–9
62: + (or - in Base64URL)
63: / (or _ in Base64URL)
0 to 63) is substituted by its corresponding character from the Base64 alphabet.==).=).Plaintext: "Man"
ASCII: 'M' (77) 'a' (97) 'n' (110)
Binary: 0 1 0 0 1 1 0 1 0 1 1 0 0 0 0 1 0 1 1 0 1 1 1 0
6-Bit Split: [010011] [010110] [000101] [101110]
Decimal: 19 22 5 46
Base64: 'T' 'W' 'F' 'u' => "TWFu"
Standard Base64 contains two characters that present severe integration hurdles on the web:
+) is interpreted by query string parsers as an encoded space character./) is the universal path separator for file systems and URL routing.To solve this, Base64URL (RFC 4648 §5) swaps + for - and / for _, and typically strips the trailing padding = characters. Base64URL is the foundation for modern web specifications, including JSON Web Tokens (JWT), OAuth 2.0 PKCE code verifiers, and WebAuthn credentials.
// Safe UTF-8 Base64 Encoding in modern JavaScript/TypeScript
export function utf8ToBase64(text: string): string {
const bytes = new TextEncoder().encode(text);
const binString = Array.from(bytes, (byte) => String.fromCharCode(byte)).join('');
return btoa(binString);
}
// Convert Standard Base64 to URL-Safe Base64 (Base64URL)
export function toBase64Url(base64: string): string {
return base64
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '');
}
// Decode Base64 back to UTF-8 string
export function base64ToUtf8(base64: string): string {
const standard = base64.replace(/-/g, '+').replace(/_/g, '/');
const binString = atob(standard);
const bytes = Uint8Array.from(binString, (m) => m.charCodeAt(0));
return new TextDecoder().decode(bytes);
}
import base64
# Standard Base64
raw_bytes = b"Hello, World!"
encoded = base64.b64encode(raw_bytes).decode("ascii") # "SGVsbG8sIFdvcmxkIQ=="
decoded = base64.b64decode(encoded)
# Base64URL (URL-Safe)
url_safe = base64.urlsafe_b64encode(raw_bytes).decode("ascii")
window.btoa() throws a DOMException: The string to be encoded contains characters outside of the Latin1 range. Always encode text to a UTF-8 byte array using TextEncoder first.No. Base64 is neither encryption nor compression. It is an encoding format designed for data interchange. It provides no secrecy (it can be decoded by anyone) and actually increases file size by approximately 33%, the opposite of compression.
= characters?The equal sign (=) is a padding character. Because Base64 processes data in 3-byte (24-bit) chunks, inputs whose lengths are not cleanly divisible by 3 require padding. One = signifies that 2 bytes were encoded; two == signify that only 1 byte was encoded.
Standard Base64 contains + and /, which interfere with URL paths and query parameters. For example, web servers often parse + as a space, corrupting the payload. Base64URL replaces + with - and / with _, allowing safe transmission in URLs, cookies, and HTTP headers without needing secondary URL Encoding.
Yes. Any arbitrary file format—including PNG, JPEG, PDF, WASM binaries, and cryptographic keys—consists of binary bytes that can be converted to Base64 and reconstructed with zero data loss. Try it yourself with our client-side Base64 Tool.
Free, browser-based utilities to test, generate, and inspect Base64 Encoding payloads directly.
Encode and decode Base64 strings, files, and data URIs instantly.
Encode, decode, and parse URLs and query strings instantly.
Decode, inspect, and validate JWT tokens with claim analysis.