Base64 Cleaner
Free online Base64 cleaner tool that removes newlines, spaces, invisible characters and other invalid content from Base64 strings. Supports three independent options: remove whitespace, remove special characters, auto-complete padding. Outputs Base64 strictly conforming to RFC 4648.
Related
What is Base64 Cleaning?
Base64 cleaning is the operation of removing all invalid and redundant characters from a Base64 string. The goal is to output pure Base64 strictly conforming to RFC 4648 standard, making it easy to transfer, store, and decode between different systems.
Why clean: Base64 from different sources often gets mixed with invalid characters. ① Newlines (\n, \r\n) — email attachments, database fields, log output; ② Spaces and tabs — manual pasting, copying from Excel; ③ UTF-8 BOM (EF BB BF) — text files saved by Windows; ④ Full-width symbols, Chinese punctuation — copy-paste errors. All of these trigger decoder errors.
Three cleaning options: ① Remove whitespace (spaces, \n, \r, \t) — handles newlines and spaces; ② Remove special characters — keeps only Base64 alphabet A-Z a-z 0-9 + / = - _; ③ Auto-complete padding — makes result length a multiple of 4. The three options can be checked independently and combined as needed.
Typical uses: ① API debugging — clean when pasting Base64 returned from third-party interfaces that causes errors; ② Database import — remove extra spaces from Excel copying; ③ Preprocessing before decoding — avoid InvalidCharacterError from atob(); ④ JWT / Data URL normalization — handle cross-system transmission differences.
Use Cases
- Preprocessing before decoding: Clean Base64 with newlines or spaces from third-party APIs, JWT, and logs into directly decodable form to avoid InvalidCharacterError.
- Excel/email paste repair: Remove extra spaces, tabs, and newlines mixed in when copying Base64 from Excel cells or email body.
- JWT token cleaning: Normalize multi-line JWT three-segment strings (header.payload.signature) into single lines, removing extra whitespace.
- MIME attachment processing: Clean up the auto-wrapped-every-76-characters format in email attachment Base64 for easier subsequent decoding.
- URL Safe compatibility: Preserves - and _ characters so Base64 in JWT, URL paths, and filenames is not deleted accidentally.
- Preprocessing before batch cleaning: Use in conjunction with base64-format / base64-padding, clean first then format or complete padding.
How to Use
- Paste or enter noisy Base64 strings (can contain newlines, spaces and other invalid characters).
- Check cleaning options as needed: Remove whitespace, Remove special characters, Auto-complete padding (all three enabled by default).
- View the output on the right: Displays cleaned Base64, character counts, number of characters removed, and decoding validity in real time.
- Copy the result to clipboard, or download as .txt file for subsequent processing.
Features
- Remove whitespace option: Automatically removes spaces, \n, \r, and \t, handling email attachments, Excel pasting and other scenarios.
- Remove special characters option: Keeps only 66 legal Base64 characters: A-Z a-z 0-9 + / = - _.
- Auto-complete padding: Optionally make the result length a multiple of 4 to fix length errors.
- Three independent stackable options: Check as needed to flexibly handle different contamination scenarios.
- URL Safe character preservation: Does not accidentally delete - and _, avoiding character loss in JWT/URL scenarios.
- Real-time validation output: Uses browser atob() to detect whether output is decodable, status displayed in real time.
- Character count and removal feedback: Shows real-time input/output character counts, number of characters removed, and decodability status.
- Local browser processing: All cleaning operations are done locally; original Base64 is never uploaded to any server.
Best Practices
Clean first, then use padding tool if needed
Cleaning only removes invalid characters and optionally completes padding. If Base64 has both newlines and missing padding, it is recommended to first check all three cleaning options, then observe whether the output length is still not a multiple of 4. If there are still padding anomalies, you can use the dedicated padding tool.
Process JWT token three segments separately
JWT is a whole of three Base64URL segments (header.payload.signature) connected by dots. When cleaning, all three segments need whitespace removed, but do not insert extra characters between segments, otherwise signature verification will fail. It is recommended to split by dots first before pasting, clean segment by segment, then reassemble.
Do not check "Remove special characters" for URL Safe input
URL Safe Base64 uses - and _ instead of + and /. This tool preserves all four characters by default, but if you manually set a stricter character whitelist (only allowing +/), URL Safe input will be corrupted. If unsure about the character set, first disable "Remove special characters" and only keep "Remove whitespace".
Still getting errors after cleaning → Check encoding and BOM
If atob() still throws InvalidCharacterError after cleaning, it may be UTF-8 BOM (EF BB BF) or UTF-16 byte order residue. The "Remove whitespace" option of this tool does not target BOM. It is recommended to re-decode as UTF-8 using TextDecoder in the browser console and then clean again.
BOM source identification: Windows saved txt files
If Base64 was obtained by saving as UTF-8 from Windows Notepad, the first 3 bytes (EF BB BF) are BOM. Even after cleaning whitespace and newlines, atob may still fail to recognize. Solution: Re-save as UTF-8 without BOM format using VS Code or PowerShell.
Show before-and-after comparisons during teaching and documentation demonstrations
Base64 cleaning is a common pain point in teaching. It is recommended to include both the before-cleaning and after-cleaning Base64 in documentation, along with character count and decodability status comparisons, to let readers intuitively understand the effect of each option.
FAQ
Does Base64 cleaning change the original bytes?
No, it does not delete valid Base64 characters. Cleaning only removes invalid characters (whitespace, newlines, non-Base64 characters) and never modifies valid characters in the middle. If only removing whitespace and illegal characters, the byte content before and after cleaning is exactly the same. If "Auto-complete padding" is checked, only = is appended at the end, which does not affect original bytes.
What is the difference between the three cleaning options?
Remove whitespace: removes spaces, \n, \r, \t (spaces, newlines, carriage returns, tabs). Remove special characters: keeps only 66 legal Base64 characters A-Z a-z 0-9 + / = - _. Auto-complete padding: appends = at the end to make length a multiple of 4. The three options are independent and combinable.
Why does atob() throw InvalidCharacterError?
Common causes: ① Contains Chinese, Unicode emoji or other non-ASCII characters; ② Contains newlines or spaces (common when copying from Excel, pasting from email); ③ Mixed Base64URL characters (- _); ④ Length is not a multiple of 4. Cleaning in this tool solves the first 3 problems, and the padding tool solves the 4th.
Does cleaning remove padding?
No. = is a legal Base64 character, and the "Remove special characters" option of this tool explicitly preserves =. If you want to remove padding, please use the dedicated padding tool (base64-padding) and switch to "Remove padding" mode.
How to clean when there are newlines?
Just leave "Remove whitespace" checked by default. Newline characters (\n / \r\n) as well as tabs and spaces will be removed. If you need to preserve newlines (MIME email attachment format), disable the "Remove whitespace" option.
Can this tool handle UTF-8 BOM?
BOM (EF BB BF) is Unicode character U+FEFF. The "Remove whitespace" in this tool uses regex for spaces, \n, \r, \t which does not include U+FEFF, so BOM may remain. If you encounter InvalidCharacterError caused by BOM, it is recommended to first remove BOM using TextDecoder in code or browser console.
Does it convert between URL Safe and standard Base64 characters?
No. The "Remove special characters" option of this tool preserves + / - _ all four characters, only doing denoising without active conversion. If you need URL Safe ↔ standard character conversion, please use the dedicated Base64URL tool (base64-url-safe).
Is my content uploaded to a server?
No. All cleaning logic runs locally in the browser, and the original Base64 string never leaves your device. You can safely use it to process sensitive data (credentials, keys, tokens).
Can I clean multiple Base64 segments at once?
This tool provides a single-segment cleaning interface. If you have multiple Base64 segments to clean, it is recommended to call this tool's logic in a loop, or use corresponding command-line tools (such as the base64 command). For batch encode/decode, please use base64-batch-encode / base64-batch-decode.
Troubleshooting
atob still throws error after cleaning
It may be a length issue (not multiple of 4) or BOM/encoding residue. First confirm that "Auto-complete padding" is checked. If it still errors, try re-decoding as UTF-8 using TextDecoder in the browser console, remove BOM, then clean again.
Length changed after cleaning, but decoding still fails
It is possible that the original content is not standard Base64, for example Base32/Base58/Base85. Please confirm the encoding format of the original data and switch to the corresponding tool. You can also try testing whether the original string can be re-encoded with btoa before using atob.
Very few characters left after cleaning
It is likely that the "Remove special characters" option is too strict, removing + / - _ as well. Please check if you accidentally disabled the character whitelist; this tool preserves all 66 legal Base64 characters by default. If input is URL Safe, just disable "Remove special characters".
No output after pasting
The input may consist entirely of whitespace characters (only spaces/newlines/tabs). This tool's "Remove whitespace" option removes all of them leaving an empty string. Please check if the original input contains at least one Base64 character (A-Z a-z 0-9 + / =).
Glossary
- UTF-8 BOM
- Byte Order Mark. A 3-byte prefix (0xEF 0xBB 0xBF) appended by Windows when saving UTF-8 text, which causes Base64 decoders to treat the first character as an illegal byte.
- URL Safe Base64
- Base64 URL-safe variant defined in RFC 4648 §5, replacing + and / with - and _. The "Remove special characters" option in this tool preserves all four of these characters to avoid accidental deletion.
- Newline characters
- \r\n (Windows) and \n (Unix/macOS). MIME Base64 for email attachments typically wraps every 76 characters, which needs to be removed during cleaning.
- Valid Base64 characters
- Standard Base64 character set is A-Z, a-z, 0-9, +, /, = (padding), plus - and _ from the URL Safe variant, totaling 66 legal characters.
- InvalidCharacterError
- The decoding error thrown by the browser's atob() function. It is triggered when the Base64 string contains characters outside the legal character table (Chinese characters, spaces, special symbols, etc.).
Base64 Character Set and Preservation Rules
Legal character table preserved by this tool's "Remove special characters" option.
| Character Type | Characters | Preservation Rule |
|---|---|---|
Letters | A-Z, a-z | 52 characters, always preserved |
Digits | 0-9 | 10 characters, always preserved |
Standard Base64 symbols | + / | 2 characters, always preserved |
URL Safe symbols | - _ | 2 characters, preserved in URLSafe scenarios |
Padding | = | Trailing padding, always preserved |
Whitespace | spaces, \n, \r, \t | Removed by "Remove whitespace" option |
Others | Chinese / emoji / BOM etc. | Removed by "Remove special characters" option |
5 Common Sources of Base64 Contamination
Understand how invalid content gets mixed into Base64 strings.
| Contamination Source | Mixed-in Content | Recommended Option |
|---|---|---|
Email attachments | \r\n every 76 characters | Remove whitespace |
Excel / database paste | leading/trailing spaces / tabs | Remove whitespace |
Windows txt files | UTF-8 BOM (EF BB BF) | Remove special characters + manually remove BOM |
URL / filenames | + / character conflicts | Preserve URLSafe (convert with base64-url-safe) |
Logs / trace output | debug prefixes / suffixes | Remove special characters |
3 Cleaning Options Comparison
The three options are independent and stackable; use in combination as needed.
| Option | Behavior | Typical Scenario |
|---|---|---|
Remove whitespace | Remove spaces, \n, \r, \t | Email / Excel / logs |
Remove special characters | Keep only Base64 alphabet | Mixed Chinese / emoji / BOM |
Auto-complete padding | Append = at end to multiple of 4 | Length not multiple of 4 |
Authoritative References
- Secure String Comparison
- Binary Converter
- Caesar Cipher
- Morse Code Translator
- Hex Converter
- Video to Base64
- Base64 to Video
- Image to Base64
- Base64 to Image
- Text to Base64
- Base64 to Text
- File Hash Checker
- File to Base64
- Base64 to File
- Audio to Base64
- Base64 to Audio
- AES Encrypt / Decrypt
- DES Encrypt Decrypt
- Base32 Encoder Decoder
- Base58 Encode Decode
- Base64 Encode
- Base64 Decode
- Base64 Diff Checker
- Base64 Split
- Base64 Multi-line Merge
- Base64 Formatter
- Base64 Validation
- Base64 Batch Encode
- Base64 Batch Decoder
- Base64 Cleaner
- Base64 Padding Tool
- Base64 Length Statistics
- Base64 to HEX
- Base64 DataURL Converter
- Base64-Hex Converter
- Base85 Encoder
- HMAC Generator & Verifier
- PBKDF2 Key Derivation
- MD5 Hash
- SHA-256 Hash
- SHA1 Hash
- SHA512 Hash
- JWT Decode, Verify & Generate
- HTML Encode Decode
- Unicode Escape
- URL Encode
- URL Safe Base64
- MIME Base64
- Java Obfuscator
- JS Obfuscator
- PHP Obfuscator
- Python Obfuscator