Base64 Encoder / Decoder
Encode text to Base64 or decode Base64 strings back to plain text. Paste your input and choose the operation.
About Base64 Encoder / Decoder
What Is It?
Base64 is a binary-to-text encoding scheme that represents binary data as a string of 64 printable ASCII characters. It uses an alphabet of A-Z, a-z, 0-9, and two additional characters (typically + and /), with = used for padding. Every 3 bytes of binary input produce exactly 4 Base64 characters — which is why Base64 output is always about 33% larger than the original binary data. This 4:3 expansion is the cost of making arbitrary binary data safe for transport through text-only channels. Base64 is not encryption — it provides zero confidentiality. Anyone can decode it back to the original bytes with no key required. Think of it like putting a binary file into a text envelope for safe mailing.
How Does It Work?
The encoding process works in 24-bit chunks. Take three bytes (24 bits), split them into four 6-bit groups, and map each 6-bit value (0-63) to a character in the Base64 alphabet. If the input isn't a multiple of 3 bytes, padding with = characters fills the gap: one padding = for a single leftover byte, two == for two leftover bytes. Decoding reverses the process. Different Base64 variants exist: the standard RFC 4648 version uses + and /, while the "URL-safe" variant swaps in - and _ to avoid issues in query strings and filenames. Some implementations — notably JSON Web Tokens (JWT) — use the URL-safe variant and strip the trailing padding entirely.
Common Use Cases
Data URIs: Embedding images directly in HTML or CSS as data:image/png;base64,iVBORw0KG... avoids an extra HTTP request for small icons and logos. Email attachments: MIME uses Base64 to encode binary attachments so they survive transit through 7-bit SMTP servers that would otherwise corrupt raw binary. API authentication: HTTP Basic Auth encodes username:password in Base64. It's not secure by itself (always pair with HTTPS), but it prevents special characters in credentials from breaking the HTTP header format. JSON Web Tokens: Each segment of a JWT (header, payload, signature) is Base64URL-encoded. Storing binary in text formats: Embedding images in JSON responses, storing small binary blobs in databases that only accept text, or encoding cryptographic keys as PEM files — those -----BEGIN CERTIFICATE----- blocks are just Base64-wrapped DER binaries.
Tips and Best Practices
When encoding for URLs, use the URL-safe variant (- and _) and consider stripping padding. Most Base64 decoders handle missing padding gracefully. When decoding, always validate the input first — malformed Base64 can produce garbage output. Watch out for whitespace and line breaks that may have been inserted by email clients or text editors; strip them before decoding. Also note that Base64 output is case-sensitive: a (value 26) is completely different from A (value 0). If you're comparing Base64 strings for equality, a simple byte comparison works — no need to normalize case.
Frequently Asked Questions
Is Base64 the same as encryption? No. Base64 is encoding, not encryption. Anyone can decode it back instantly. If you need confidentiality, use actual encryption (AES, ChaCha20) before encoding. Why does Base64 end with ==? The = signs are padding, ensuring the output length is always a multiple of 4 characters. They carry no data — they just tell the decoder how many bytes to discard from the last 24-bit group. How does Base64 compare to hex encoding? Hex (Base16) uses 2 characters per byte, producing 100% overhead. Base64 uses 4 characters per 3 bytes, producing about 33% overhead. So Base64 is more compact. But hex is easier to read and debug because each byte maps cleanly to exactly two characters.