Base64 Decoder

Input

Output

Overview

The Base64 Decoder reverses the Base64 encoding process, transforming an ASCII-safe Base64 string into the original byte sequence and then decoding those bytes as UTF-8 text. Base64 encoding is used extensively to embed binary data—images, fonts, certificates—into text formats like JSON, XML, or HTML. The decoder strips out any line breaks or spaces inserted for readability, supports both the standard and URL-safe alphabets, and gracefully handles padding characters (‘=’). This tool is essential whenever you need to recover human-readable text or binary assets from Base64-encoded sources.
What Is Base64?
Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 ASCII characters: A–Z, a–z, 0–9, plus (+) and slash (/), with equals (=) for padding. It encodes every three bytes of input data into four characters. This ensures safe transmission over media that only support text, such as email bodies (MIME) or JSON payloads. By recovering the original byte stream, you can reconstruct files, certificates, or plain text without loss.
Supported Variants and Alphabets
There are two main Base64 alphabets: the standard variant (with + and /) and the URL-safe variant (with – and _). The decoder auto-detects URL-safe characters and normalizes them to the standard alphabet before decoding. It also ignores line breaks, spaces, and tab characters, allowing you to decode content formatted for readability or legacy specifications. Padding rules (‘=’) indicate missing bytes in the final block and are handled according to RFC 4648.
How It Works
1. **Normalization**: Replace URL-safe characters (“–”→“+”, “_”→“/”) and remove whitespace. 2. **Validation**: Verify that the input length is a multiple of 4 (or pad if necessary). 3. **Map to Values**: Convert each Base64 character to its 6-bit integer value. 4. **Reassemble Bytes**: Take each group of four 6-bit values, combine into three 8-bit bytes. 5. **Padding Removal**: Discard padding bytes indicated by ‘=’. 6. **UTF-8 Decoding**: Interpret the resulting byte array as UTF-8 and return the decoded string.
Input Format
Input should be a valid Base64 string. Allowed characters: A–Z, a–z, 0–9, +, / (or –, _ in URL-safe mode), and up to two padding characters (‘=’) at the end. The decoder tolerates line breaks, spaces, and optional padding. Invalid characters or malformed padding can be handled in strict mode (throwing errors) or lenient mode (skipping malformed segments).
Output Format
The output is a standard UTF-8 string. Each reconstructed byte is interpreted as part of a UTF-8 code point, recovering the original characters, including international scripts, emojis, control characters, and binary blobs. Invalid byte sequences produce the Unicode replacement character (�) or throw errors in strict mode, depending on configuration.
Error Handling & Modes
In **strict mode**, the decoder validates every character and padding position, throwing an error with a descriptive message if the input is malformed—such as incorrect padding length or invalid characters. In **lenient mode**, it issues warnings in the console or log and skips over invalid segments, inserting replacement characters for unmapped bytes. This flexibility helps in processing real-world data that may have been corrupted or generated by non-standard implementations.
Performance Considerations
Decoding Base64 is a linear-time operation (O(n)) in the length of the input string. For small to medium payloads (up to a few megabytes), performance is effectively instantaneous in modern JavaScript engines. For very large inputs (>10MB) in a single chunk, consider streaming the input or performing the decoding inside a Web Worker to avoid blocking the main UI thread and to reduce peak memory usage.
Security Considerations
Base64 is not encryption or signing—it offers no confidentiality or integrity guarantees. Malicious content can be hidden within Base64-encoded data, so always validate and sanitize decoded text before inserting it into HTML, SQL queries, or system calls. Protect against denial-of-service by enforcing maximum input lengths and timeout thresholds for decoding operations.
Use Cases
Common scenarios include decoding image or file attachments embedded in JSON or HTML, extracting PEM-format certificates from Base64 blocks, and processing API responses that return binary data as Base64 strings. It’s also invaluable for developers inspecting HTTP traffic, security researchers analyzing malware payloads, and automation scripts that convert encoded configuration values back into usable formats.
Best Practices
Always decode Base64-encoded data outside of user-facing contexts until you validate its content. Use built-in browser methods (`atob`) or Node.js buffers (`Buffer.from(input, 'base64')`) for reliable decoding when possible, and reserve custom decoders for specialized modes or educational purposes. Normalize padding and character case before decoding to ensure consistent behavior across environments.

Example

`aGVsbG8gd29ybGQ=` → `hello world`