Base64 Decoder — Decode Base64 Strings Online
Decode Base64 encoded strings to plain text instantly. Supports standard and URL-safe Base64.
About Base64 Decoder — Decode Base64 Strings Online
Base64 Decoder converts Base64-encoded strings back to readable text in real time. Supports Unicode and Japanese via UTF-8. Invalid Base64 is flagged instantly — no sign-up, nothing sent to a server.
How to Use
- 1Paste the Base64-encoded string into the left area.
- 2The decoded text appears on the right instantly.
- 3Click "Copy" to copy the result to your clipboard.
Features
- Real-time decoding — results appear as you type
- Full Unicode and Japanese support via UTF-8
- Invalid Base64 detected instantly with an error badge
- Runs entirely in your browser — no upload required
Understanding Base64 Decoding
Base64 decoding reverses the encoding process, converting a Base64 string back to its original binary data or text. Knowing how decoding works and what constitutes valid input helps you handle Base64 data reliably in your applications.
The Decoding Algorithm
Base64 decoding reads the encoded string four characters at a time. Each character is looked up in the Base64 alphabet table to recover the original 6-bit value. The four 6-bit values are then combined into three bytes of original data. Padding characters (=) at the end signal that the last group had fewer than three original bytes: one = means the last group produced two bytes, and == means it produced only one byte. The decoder must validate that every character in the input belongs to the Base64 alphabet, that = appears only at the end of the string, and that the total length is consistent. A valid Base64 string always has a total length (including padding) that is a multiple of four. Strings that fail these checks are invalid and cannot be decoded correctly without guessing about the missing data.
Identifying Valid Base64 Strings
A valid standard Base64 string consists only of the characters A-Z, a-z, 0-9, +, and /, followed by zero, one, or two = padding characters at the end. Its total length including padding must be a multiple of four. URL-safe Base64 uses - instead of + and _ instead of /, and may omit the = padding entirely. If you receive a string that looks like Base64 but fails to decode, the most common causes are whitespace or newlines inserted by line-wrapping (common in email-formatted Base64), mixing of standard and URL-safe alphabets, missing or extra padding characters, and corruption or truncation during transmission. Stripping all whitespace and ensuring the correct alphabet and padding are present usually resolves decoding failures in practice.
Detecting and Handling Invalid Base64 Data
Production code that decodes Base64 must handle invalid input gracefully. Understanding the failure modes helps you write robust error handling and communicate clear error messages to users.
Common Sources of Invalid Base64
Invalid Base64 data arises from several common sources. Line wrapping: MIME-encoded Base64, used in email, inserts a newline every 76 characters; the newlines must be stripped before decoding in contexts that do not expect them. Alphabet mismatch: standard Base64 uses + and /, while URL-safe Base64 uses - and _. Passing URL-safe Base64 to a standard decoder (or vice versa) causes failures for strings containing those differing characters. Truncation: if a Base64 string is cut off at a fixed character limit, the resulting fragment is not decodable. Padding errors: some systems strip the = padding from Base64 strings for use in URLs; a decoder that strictly requires padding will fail on such input. Understanding which variant your data source produces lets you pre-process the input appropriately before decoding.
Error Handling in Code
In JavaScript, atob() throws a DOMException if the input is not valid Base64, so always wrap it in a try/catch block. In Python, base64.b64decode() raises a binascii.Error on invalid input; using validate=True makes it stricter about alphabet and padding conformance. In PHP, base64_decode() returns false on failure when the strict parameter is set to true, so always check the return value rather than assuming success. When building a user-facing application, catch decoding errors and display a clear message explaining that the input is not valid Base64, rather than showing a cryptic exception trace or silently returning empty output. This tool shows an error badge for invalid input so you can immediately identify malformed strings.
Security Considerations When Decoding
Decoding Base64 from untrusted sources carries security risks that developers often overlook. A Base64-encoded string can contain any bytes after decoding — including null bytes, binary sequences, executable code, or malicious HTML and script content. Never pass decoded output directly to eval(), innerHTML, or system command functions without sanitization. When decoding user-supplied Base64 that is supposed to represent a specific data type such as a JSON object or an image, validate the decoded output against the expected format before processing it further. Also enforce maximum size limits on input before decoding to prevent memory exhaustion in server-side code that handles untrusted requests, since large Base64 strings expand to substantial binary data after decoding.
FAQ
- How do I know if a string is Base64?
- Base64 strings contain only A-Z, a-z, 0-9, +, /, and = padding characters. If it matches that pattern, it is likely Base64.
- Can I decode Base64-encoded images?
- This tool decodes to text. For Base64-encoded images, use the Base64 to Image tool instead.
- What if decoding fails?
- An error badge appears. This usually means the input is not valid Base64 — check for extra spaces or unsupported characters.
- What causes "Invalid Base64 string" errors when decoding?
- Common causes include: extra whitespace or newline characters in the encoded string (some encoders add line breaks every 76 characters per MIME standard), incorrect padding (missing = at the end), use of URL-safe Base64 characters (- and _ instead of + and /), or simply corrupted or incomplete data. Try trimming whitespace, adding or removing = padding, and replacing - with + and _ with / if the data came from a URL-safe Base64 source.
- Can this tool decode Base64-encoded images?
- Yes. If you have a Base64-encoded image string (typically from a data: URL like data:image/png;base64,...), remove the data: prefix and paste just the Base64 string into the decoder. The decoded output will be the raw binary image data. To view the image directly, use a dedicated Base64 image decoder tool that can render the binary output as an image preview.
Found a bug or something not working as expected?
Report a bug →