Base64 Encoder / Decoder
Encode text or files to Base64, or decode Base64 back to plain text — instantly, in your browser.
Drop any file here to encode as Base64
or
What Is Base64? A Complete Technical Overview
Base64 is a binary-to-text encoding scheme that converts binary data into a stream of 64 printable ASCII characters. The standard alphabet consists of A–Z (26 chars), a–z (26 chars), 0–9 (10 chars), + (62nd), and / (63rd). The 64th position is padding with =.
The core idea: instead of sending raw bytes — which may contain unprintable or control characters — every 3 bytes (24 bits) are mapped into 4 Base64 characters, each representing 6 bits. This guarantees the output uses only safe, universally transmissible characters.
Base64 was introduced in the early 1990s for Privacy-Enhanced Mail (PEM) and later adopted by MIME (Multipurpose Internet Mail Extensions). Today, it is a cornerstone of web development, API design, and data serialization.
How Base64 Works Under the Hood
Every byte is 8 bits. Base64 looks at 3 bytes at a time (24 bits), splits those 24 bits into 4 groups of 6 bits, then maps each 6-bit value (0–63) to a character in the Base64 alphabet. Example with the text "Man":
If the input length is not a multiple of 3, padding characters (=) are appended to make the output length a multiple of 4. One = means the last group contained 2 bytes; two = means it contained only 1 byte.
Why Base64 Exists
The internet was built on text-based protocols: HTTP, SMTP, and early JSON all assume 7-bit ASCII or UTF-8. Binary data — images, compressed files, cryptographic keys — can break these protocols. Control characters might be misinterpreted, line breaks altered, or null bytes could terminate a string early.
Base64 solves this by ensuring every transmitted character is safe. It trades size for safety: a 33% size increase in exchange for guaranteed compatibility across virtually every system built in the last 30 years.
Why Use Base64? Key Benefits & Trade-offs
Advantages
- Universal compatibility — works everywhere: email servers, HTTP headers, JSON, XML, and legacy mainframe systems.
- No data corruption — only printable ASCII characters, so no intermediate system will misinterpret or modify the encoded data.
- Simple to implement — every modern language includes built-in Base64 functions:
btoa/atobin JavaScript,base64in Python,base64_encodein PHP. - URL-safe variant available — replaces
+and/with-and_, enabling use in URLs, filenames, and JWTs.
Disadvantages to Consider
- Size overhead — increases data size by ~33%. A 3 MB image becomes 4 MB of Base64.
- Not encryption — anyone who sees the Base64 string can decode it instantly. Never use it to protect secrets.
- CPU cost — encoding and decoding large files consumes CPU cycles, especially on mobile or embedded systems.
Rule of thumb: Use Base64 for small binary blobs (under 100 KB), API tokens, email attachments, and data URIs. Avoid it for large media files or real-time streaming.
Common Use Cases
username:password as Base64 in the Authorization header. Many API keys are Base64-encoded byte sequences.data:image/png;base64,… — no separate HTTP request needed for small icons and logos.-----BEGIN … ----- headers.1. API Authentication (HTTP Basic & Bearer Tokens)
HTTP Basic Authentication concatenates username:password, encodes it in Base64, and sends it in the Authorization header:
Modern APIs also issue Bearer tokens that are Base64-encoded JWTs. A JWT has three URL-safe Base64 parts separated by dots: header.payload.signature.
2. Email Attachments via MIME
SMTP was designed for 7-bit ASCII text. Binary attachments would be corrupted during transit. MIME solves this by splitting the binary file into chunks, encoding each with Base64, and adding headers like Content-Transfer-Encoding: base64. Email clients reassemble and decode the parts automatically.
3. Data URIs: Embedding Assets in HTML/CSS
A Data URI embeds a file directly into a web page, eliminating an extra HTTP request. Format:
Best for assets under 2 KB. Larger assets should remain as separate files since Data URIs are not cached independently from the HTML/CSS file.
4. Cryptographic Keys & Certificates (PEM Format)
PEM is the standard for storing cryptographic objects. The data between the header and footer is Base64-encoded DER binary, used by OpenSSL, curl, and virtually all web servers:
5. Binary Data in JSON
JSON has no binary type. To send binary payloads — thumbnails, encrypted chunks, cryptographic nonces — inside a JSON body, encode them as Base64 strings:
6. URL-Safe Tokens (JWT, OAuth, API Keys)
Standard Base64 contains +, /, and =, which have special meanings in URLs. URL-safe Base64 (RFC 4648 §5) eliminates this problem. A real JWT looks like:
Notice no +, /, or = — this token is safe to include directly as a URL query parameter.
Standard vs. URL-safe Base64
Standard Base64 uses + and / as the 62nd and 63rd characters, and = for padding. These characters have special meaning in URLs, so URL-safe Base64 (RFC 4648 §5) swaps them:
+→-(hyphen)/→_(underscore)=padding is omitted
URL-safe Base64 is used in JWTs, OAuth tokens, and any situation where the encoded string appears in a URL or filename. Toggle the "URL-safe" checkbox in the tool above to switch modes.
Code Examples Across Languages
JavaScript (Browser & Node.js)
Python 3
PHP
Command Line (Linux / macOS / Windows WSL)
Security & Privacy Notes
Base64 is not encryption.
Never store passwords, credit card numbers, or session tokens in Base64 without additional encryption. Base64 is reversible by anyone with a browser or command line in milliseconds.
Always use HTTPS when transmitting Base64 data. Although Base64 itself is not secret, an attacker intercepting traffic can read the decoded contents just as easily as the encoded version.
Be careful with large files. Encoding a 50 MB file in your browser may cause memory issues or freezes. Keep files under 10 MB for the best experience.
This tool processes everything locally — no file or text is ever uploaded to any server. You can verify this by disconnecting from the internet after the page loads; the tool still works fully offline.
Frequently Asked Questions
Is Base64 encoding secure for passwords?
No. Base64 is plain encoding, not hashing or encryption. Anyone who sees the Base64 string can decode it instantly. Always use proper password hashing (bcrypt, Argon2, PBKDF2) and never transmit passwords in Base64 without TLS.
Why does my Base64 output end with = or ==?
These are padding characters. Base64 requires the output length to be a multiple of 4. If the original data length is not a multiple of 3, one or two = characters are appended. One = means the last group had 2 bytes of input; two = means it had 1 byte.
Can I decode a Base64 string that contains spaces or line breaks?
Yes. This tool automatically strips whitespace before decoding. If you are decoding manually in code, remove \n, \r, and spaces first, as some decoders are strict about this.
What happens if I try to decode invalid Base64?
This tool shows an error: "Invalid Base64 — contains characters outside the Base64 alphabet." Common causes: using URL-safe characters (- or _) without enabling URL-safe mode, missing padding, or extra non-whitespace characters.
Does Base64 work with emojis and Chinese characters?
Yes. This tool uses JavaScript TextEncoder and TextDecoder, which fully support UTF-8. Emojis (😀), Chinese (中文), Arabic (مرحبا), and all other Unicode characters are encoded and decoded correctly.
How do I create a Data URI for an image?
Use the File Encoder section above to encode your image. Then prefix the result with data:image/png;base64, (change image/png to match your format: image/jpeg, image/gif, image/webp). Use the full string as the src attribute of an <img> tag.
Why is my Base64 string longer than the original file?
Base64 expands data by roughly 33%. A 100 KB file becomes about 133 KB of Base64. This is expected — 6 bits of output represent 8 bits of input, so every 3 input bytes become 4 output characters (4/3 ≈ 1.33).
Can I encode a folder or multiple files at once?
Not directly. You would need to encode each file separately, or combine them into a single archive (ZIP, TAR) first and then encode that archive. This tool handles one file at a time to keep memory usage predictable.
What is the maximum file size this tool can handle?
The limit depends on your device's RAM and browser. For smooth performance, keep files under 10 MB. Very large files (100 MB+) may cause the browser tab to freeze or crash, as all processing happens in-memory in your browser.
Is there a difference between Base64 on Windows, Linux, and macOS?
No. The Base64 algorithm is identical across all operating systems. However, line endings (\r\n on Windows vs \n on Unix) may differ when saving encoded output to text files. This tool follows standard conventions and produces consistent results everywhere.
Related Developer & Utility Tools
More free tools to speed up your workflow — all run locally in your browser.