Base64 Encoder

Encode and decode Base64 strings

What is Base64?

Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. It's commonly used to encode data for transmission over media that are designed to deal with text.

Common Use Cases:

  • • Encoding images in HTML/CSS (data URLs)
  • • Embedding files in XML or JSON
  • • Email attachments (MIME)
  • • Basic authentication headers

How It Works

Base64 encoding works by converting binary data into a set of 64 ASCII characters (A-Z, a-z, 0-9, +, and /). The encoding process takes 3 bytes of binary data (24 bits) and splits them into four 6-bit groups. Each 6-bit group maps to one of the 64 characters in the Base64 alphabet, resulting in a 4-character output for every 3 bytes of input.

The mathematical foundation uses bitwise operations: the input bytes are concatenated into a 24-bit buffer, then divided into four 6-bit indices. These indices are used to look up characters in the Base64 alphabet table. When the input length isn't divisible by 3, padding characters (=) are added to make the output length a multiple of 4.

For decoding, the process reverses: Base64 characters are converted back to their 6-bit values, concatenated into 24-bit groups, then split into three 8-bit bytes. The implementation uses JavaScript's built-in btoa() and atob() functions, with UTF-8 handling via encodeURIComponent() and decodeURIComponent() to properly handle Unicode characters.

Practical Use Cases

1. Web Development & Data URLs

Base64 encoding is essential for embedding small images directly in HTML, CSS, or JavaScript files using data URLs. This technique reduces HTTP requests by including image data inline, improving page load performance for small icons and graphics. For example: data:image/png;base64,iVBORw0KG...

2. Email Systems & MIME

Email protocols like SMTP were designed for text-only transmission. Base64 encoding allows binary attachments (PDFs, images, documents) to be transmitted through email systems by converting them to text format. This is why email attachments often appear as large blocks of Base64 text in raw email sources.

3. Authentication & API Integration

HTTP Basic Authentication uses Base64 to encode username:password combinations in the Authorization header. While not secure by itself (it's easily decoded), it's commonly used with HTTPS for simple API authentication. Format: Authorization: Basic base64(username:password)

4. Configuration Files & JSON APIs

Base64 encoding is frequently used to embed binary data in JSON or XML configuration files. This allows APIs to transmit binary content (like certificates, keys, or images) within text-based data structures without breaking the text format or requiring separate binary endpoints.

Examples & Pitfalls

✓ Correct Usage Examples

Simple text encoding:

Input: "Hello World"
Output: "SGVsbG8gV29ybGQ="

Unicode text handling:

Input: "Hello 世界 🌍"
Output: "SGVsbG8g5LiW55WMIPCfjI0="

Binary data encoding:

Input: [0x48, 0x65, 0x6C, 0x6C, 0x6F]
Output: "SGVsbG8="

✗ Common Pitfalls

Invalid character in encoded string:

Input: "SGVsbG8@V29ybGQ="
Error: Invalid character '@"

❌ Base64 only allows A-Z, a-z, 0-9, +, /, and =

Incorrect padding:

Input: "SGVsbG8V29ybGQ"
Error: Invalid string length

❌ Base64 strings must have length multiple of 4

URL-safe confusion:

Standard: "SGVsbG8+V29ybGQ="
URL-safe: "SGVsbG8-V29ybGQ="

❌ URLs need '+' replaced with '-' and '/' with '_'

Privacy & Security

This Base64 encoder/decoder operates entirely within your browser using client-side JavaScript. No data is transmitted to external servers, ensuring complete privacy for your encoded or decoded content. All encoding and decoding operations occur in your browser's JavaScript engine, making it safe for processing sensitive data such as API keys, authentication tokens, or configuration strings.

Important Security Note: Base64 encoding is not encryption. It provides no security benefits and should never be used to protect sensitive information. Base64 encoding is easily reversible and provides only obfuscation, not confidentiality. For secure data transmission, always use proper encryption methods like AES or RSA in addition to Base64 encoding when necessary.

The tool uses JavaScript's built-in btoa() and atob() functions, which are widely supported across modern browsers. For Unicode text, it implements proper UTF-8 encoding/decoding using encodeURIComponent() and decodeURIComponent() to handle international characters correctly. However, for very large binary files (over 100MB), consider using command-line tools or server-side processing to avoid browser memory limitations.

Last updated: 2026/3/14