Base64 Encoder/Decoder
Convert text to Base64 and back
Plain Text
Base64 String
About Base64
Base64 is an encoding scheme that converts binary data into ASCII text format using 64 different characters (A-Z, a-z, 0-9, +, /).
It's commonly used to encode data in URLs, emails, and data URIs. Base64 encoding increases data size by approximately 33%.
Common uses:
- Embedding images in HTML/CSS (data URIs)
- Encoding authentication credentials
- Transferring binary data over text-based protocols
- Storing complex data in JSON or XML
How It Works
Base64 is an encoding scheme that converts binary data into ASCII text format using 64 printable characters (A-Z, a-z, 0-9, +, /). It's designed to safely transmit binary data over text-based protocols like email or JSON that only support ASCII characters. The encoding increases data size by approximately 33% due to representing 8-bit bytes with 6-bit characters.
This tool uses JavaScript's built-in btoa() function for encoding (binary to ASCII) and atob() for decoding (ASCII to binary). For proper UTF-8 support, the tool first encodes strings to UTF-8 byte sequences, then applies Base64 encoding. This ensures characters from any language encode correctly, not just basic ASCII.
Base64 encoding is reversible and deterministic—the same input always produces the same output, and decoded data perfectly matches the original. However, it's not encryption. Base64 provides no security—anyone can decode it instantly. Use encryption algorithms (AES, RSA) for confidentiality, Base64 only for encoding.
This tool uses JavaScript's built-in btoa() function for encoding (binary to ASCII) and atob() for decoding (ASCII to binary). For proper UTF-8 support, the tool first encodes strings to UTF-8 byte sequences, then applies Base64 encoding. This ensures characters from any language encode correctly, not just basic ASCII.
Base64 encoding is reversible and deterministic—the same input always produces the same output, and decoded data perfectly matches the original. However, it's not encryption. Base64 provides no security—anyone can decode it instantly. Use encryption algorithms (AES, RSA) for confidentiality, Base64 only for encoding.
Use Cases
1. Embedding Images in HTML/CSS
Convert images to Base64 data URLs for embedding directly in HTML or CSS files. This eliminates separate HTTP requests for small images (icons, logos), improving page load speed by reducing network latency. Useful for email templates where external image loading may be blocked.
2. API Authentication Headers
HTTP Basic Authentication encodes credentials as Base64 in the Authorization header (format: "Basic base64(username:password)"). Many APIs use Base64-encoded tokens for authentication. While not secure without HTTPS, it's a standard format for transmitting credentials in HTTP headers.
3. Data URLs & File Storage
Base64 enables storing binary files (images, PDFs, audio) as text in databases or JSON. Convert files to Base64 strings for storage in NoSQL databases, localStorage, or API responses. This works for small files but increases storage requirements by 33% and impacts performance for large files.
4. Email Attachments (MIME)
Email protocols (SMTP) are text-based and can't transmit binary files directly. Email attachments are Base64-encoded in MIME messages to ensure safe transmission across email servers. This encoding allows binary files to travel through text-only email infrastructure without corruption.
5. Encoding Binary Data in JSON
JSON doesn't support binary data types. Base64 encoding converts binary data (encryption keys, file contents, byte arrays) into strings for JSON transmission. APIs serving files or binary data often return Base64-encoded strings that clients decode on receipt.
Convert images to Base64 data URLs for embedding directly in HTML or CSS files. This eliminates separate HTTP requests for small images (icons, logos), improving page load speed by reducing network latency. Useful for email templates where external image loading may be blocked.
2. API Authentication Headers
HTTP Basic Authentication encodes credentials as Base64 in the Authorization header (format: "Basic base64(username:password)"). Many APIs use Base64-encoded tokens for authentication. While not secure without HTTPS, it's a standard format for transmitting credentials in HTTP headers.
3. Data URLs & File Storage
Base64 enables storing binary files (images, PDFs, audio) as text in databases or JSON. Convert files to Base64 strings for storage in NoSQL databases, localStorage, or API responses. This works for small files but increases storage requirements by 33% and impacts performance for large files.
4. Email Attachments (MIME)
Email protocols (SMTP) are text-based and can't transmit binary files directly. Email attachments are Base64-encoded in MIME messages to ensure safe transmission across email servers. This encoding allows binary files to travel through text-only email infrastructure without corruption.
5. Encoding Binary Data in JSON
JSON doesn't support binary data types. Base64 encoding converts binary data (encryption keys, file contents, byte arrays) into strings for JSON transmission. APIs serving files or binary data often return Base64-encoded strings that clients decode on receipt.
Tips & Best Practices
• Base64 is not encryption: It's reversible encoding, not security. Anyone can decode Base64 instantly with no password or key. Never use Base64 alone to protect sensitive data. Encrypt first, then encode if needed for transmission.
• Use for small data only: Base64 increases size by 33%. For large files, this overhead is significant. A 10MB file becomes 13.3MB when Base64-encoded. For files over 1MB, consider direct binary transmission or compression before encoding.
• URL-safe Base64 variants exist: Standard Base64 uses +, /, and = characters that have special meaning in URLs. For URL parameters or filenames, use URL-safe Base64 (replaces + with -, / with _, removes padding =). Most libraries offer both variants.
• Always specify character encoding: When encoding text (not binary), ensure UTF-8 encoding to support international characters. ASCII-only encoding corrupts non-English text. This tool handles UTF-8 automatically, but verify when using other tools.
• Decode to validate data integrity: After encoding, decode the output to verify it matches your original input. This catches encoding errors before sending data to APIs or storing in databases.
• Mind the padding: Base64 uses = characters for padding to align data to 4-character blocks. Some systems accept Base64 without padding, others require it. If decoding fails, check if padding is missing or unexpected.
• Combine with compression for efficiency: For text or repetitive data, compress (gzip) before Base64 encoding. This often results in smaller final size than raw Base64, especially for large text documents with repetition.
• Use for small data only: Base64 increases size by 33%. For large files, this overhead is significant. A 10MB file becomes 13.3MB when Base64-encoded. For files over 1MB, consider direct binary transmission or compression before encoding.
• URL-safe Base64 variants exist: Standard Base64 uses +, /, and = characters that have special meaning in URLs. For URL parameters or filenames, use URL-safe Base64 (replaces + with -, / with _, removes padding =). Most libraries offer both variants.
• Always specify character encoding: When encoding text (not binary), ensure UTF-8 encoding to support international characters. ASCII-only encoding corrupts non-English text. This tool handles UTF-8 automatically, but verify when using other tools.
• Decode to validate data integrity: After encoding, decode the output to verify it matches your original input. This catches encoding errors before sending data to APIs or storing in databases.
• Mind the padding: Base64 uses = characters for padding to align data to 4-character blocks. Some systems accept Base64 without padding, others require it. If decoding fails, check if padding is missing or unexpected.
• Combine with compression for efficiency: For text or repetitive data, compress (gzip) before Base64 encoding. This often results in smaller final size than raw Base64, especially for large text documents with repetition.
Frequently Asked Questions
Related Tools
Explore more tools that might help you