Base64 Encoder & Decoder
Encode clear text strings into Base64 format or decode Base64 strings back to text. Supports full UTF-8 encoding (accents, emojis) 100% offline.
RFC 4648 Base64 Encoding Architecture & 6-Bit Chunking
Base64 is a binary-to-text encoding scheme defined formally by RFC 4648. It is designed to represent arbitrary sequences of binary bytes using a safe, restricted alphabet of exactly 64 printable ASCII characters (A-Z, a-z, 0-9, +, and /, with = reserved for padding).
The mathematical operation of Base64 is based on 6-bit chunking. Because an octet (byte) contains 8 bits, every group of three 8-bit bytes (24 bits total) can be divided evenly into four 6-bit chunks (4 * 6 = 24). Each 6-bit value (ranging from 0 to 63) maps directly to a character in the standard Base64 lookup index table:
- Bits
0β25map to uppercase lettersAβZ. - Bits
26β51map to lowercase lettersaβz. - Bits
52β61map to numerals0β9. - Bits
62and63map to+and/respectively.
If the input byte length is not divisible by 3, trailing padding characters (= or ==) are appended so the output length is always a multiple of 4. Because 4 ASCII characters represent 3 raw bytes, Base64 introduces a predictable 33% data size overhead.
Programmatic Base64 Encoding in JavaScript, Python & CLI
Execute UTF-8 safe Base64 encoding and decoding using these verified snippets:
// Modern JavaScript (UTF-8 Safe with TextEncoder)
function base64Encode(str) {
const bytes = new TextEncoder().encode(str);
const binString = Array.from(bytes, (byte) => String.fromCharCode(byte)).join('');
return btoa(binString);
}
function base64Decode(b64) {
const binString = atob(b64);
const bytes = Uint8Array.from(binString, (m) => m.charCodeAt(0));
return new TextDecoder().decode(bytes);
}
const encoded = base64Encode("Hello, δΈη! π");
console.log("Encoded:", encoded);
console.log("Decoded:", base64Decode(encoded));
# Python 3 base64 module
import base64
text = "Hello, δΈη! π"
# Encode
raw_bytes = text.encode("utf-8")
b64_str = base64.b64encode(raw_bytes).decode("ascii")
print("Base64:", b64_str)
# Decode
decoded_str = base64.b64decode(b64_str.encode("ascii")).decode("utf-8")
print("Original:", decoded_str)
# Bash / Terminal CLI
echo -n "Hello World" | base64
# Decode
echo -n "SGVsbG8gV29ybGQ=" | base64 --decode
UTF-8 Safety & The Native btoa() Browser Bug
A notorious trap in client-side JavaScript is that the legacy browser functions window.btoa() and window.atob() only accept characters within the Latin-1 (ASCII 0β255) code range. Attempting to encode Unicode characters like accents (Γ‘, Γ±, ΓΌ) or emojis throws a fatal DOMException: The string to be encoded contains characters outside of the Latin1 range.
Our tool implements modern TextEncoder and TextDecoder byte streaming, ensuring 100% error-free translation for all international languages and emoji characters.
Standard Base64 vs Base64URL (RFC 4648 Section 5)
In web URLs, query parameters, and JWT tokens, standard Base64 characters + and / cause routing failures, while = padding can be stripped or misinterpreted. Base64URL replaces + with hyphen (-), replaces / with underscore (_), and omits trailing = padding characters to ensure safe URL transmission.
Related Converters & Encoders
Chain Base64 Encoder & Decoder with these complementary client-side utilities from our Converters & Encoders collection:
Encode images to Base64 data strings or decode Base64 strings back to images locally. 100% secure and client-side.
Free online Base32 and Base58 encoder/decoder. Encode or decode text and hexadecimal strings offline. Standard RFC 4648 Base32 and Bitcoin Base58 supported.
Free online base converter. Transform numbers between Decimal, Hexadecimal, Binary, Octal, and custom bases (2 to 36) with arbitrary precision. 100% private and local.
Free online converter to translate plain text to binary code and binary numbers back to text. Supports customizable separators, runs 100% offline.
Frequently Asked Questions
No. Base64 is an encoding format, not encryption. It provides zero confidentiality or security. Anyone who receives a Base64 string can instantly decode it back to plaintext.
Because Base64 represents 3 bytes (24 bits) using 4 ASCII characters (32 bits). The ratio 32/24 represents an exact 33.33% size expansion.
Padding signals to the decoder how many zero-bits were added to align the final byte chunk to a 24-bit boundary.
Yes. Base64 can encode any sequence of raw bytes, including PNG, JPEG, PDF, and ZIP files, into Data URLs for embedding directly into HTML or CSS.
No. The conversion is performed 100% locally in your browser using client-side JavaScript.