Base64 Encoder

Input

Output

Overview

Base64 is a binary-to-text encoding scheme that represents binary data using 64 ASCII characters (A–Z, a–z, 0–9, +, /) plus = padding. It’s widely used to embed images in HTML/CSS, include binary attachments in email (MIME), and safely transmit byte streams over protocols that only support text. The Base64 Encoder takes any UTF-8 input string, converts it to raw bytes, and then encodes those bytes into a Base64 string, inserting line breaks or spaces if configured for readability.
Key Concepts
Each group of 3 bytes (24 bits) is split into four 6-bit values. Those 6-bit values index into the Base64 alphabet, producing four characters. If the final group has fewer than 3 bytes, padding characters (‘=’) are added to indicate the missing bytes.

Input Format

Any UTF-8 text string, including ASCII, emoji, and other Unicode characters. Internally, each character is encoded to one or more bytes according to UTF-8 rules before Base64 conversion.

Output Format

A Base64-encoded ASCII string. When `spaces: true`, the encoder breaks the output into 76-character lines or inserts spaces between each 4-character block to aid manual inspection.

How It Works

1. **UTF-8 Encode**: Convert input string to a byte array. 2. **Group Bytes**: Split into 3-byte chunks. 3. **Bit Shifting**: Extract four 6-bit segments per chunk. 4. **Alphabet Lookup**: Map each 6-bit value to a Base64 character. 5. **Padding**: Append ‘=’ for any missing bytes in the final chunk. 6. **Formatting**: Insert spaces or line breaks if enabled.

Use Cases

Web developers embed small images or fonts directly in CSS using Data URIs (`data:image/png;base64,…`). Email clients use Base64 to transport attachments safely. Cloud APIs often accept Base64 payloads for binary fields.
In security tooling, shellcode or certificates are Base64-encoded to include in JSON or XML configs. Command-line utilities and scripts rely on Base64 for cross-platform binary interoperability.

Performance Considerations

Encoding large files entirely in the browser can be memory-intensive. For inputs over several megabytes, consider streaming in Web Workers or handling on the server side.

Security Considerations

Base64 is not encryption. It provides no confidentiality or integrity guarantees. Do not use it to hide secrets—always combine with proper cryptographic algorithms when security is required.

Example

`hello world` → `aGVsbG8gd29ybGQ=`