Base64 Formatter
Free online Base64 formatter with custom line width (64/76/80/100 characters) and indent (0/2/4 spaces) for multi-line display. Perfect for reading, screenshot comparison and documentation - the original Base64 data is never altered.
Related
What is Base64 Formatting?
Base64 formatting is the act of splitting a long Base64 string into multiple lines of a chosen character width (such as 64/76/80/100) and optionally indenting each line with 0/2/4 spaces. The formatted result is easier to read, screenshot, print and document, but it does NOT change the underlying bytes - removing all line breaks and indents restores the original single-line Base64 exactly.
Why is formatting needed? Standard Base64 (RFC 4648) does not require line breaks, but in real-world use: (1) long Base64 strings overflow horizontally in ticketing systems, chat tools and Markdown documents; (2) MIME (RFC 2045) requires lines of 76 characters for email attachments; (3) multi-line display during code review makes it easier to locate stray characters; (4) screenshots and printed docs need clean alignment.
Common use cases: (1) technical documentation - embed long Base64 in Markdown / Confluence / Notion; (2) screenshot comparison - capture the full Base64 string in a PR or bug report; (3) manual review - quickly spot illegal characters (mixed-in newlines or spaces) in code review; (4) email attachments - wrap at 76 characters per line for SMTP; (5) dashboard logs - show long Base64 payloads across multiple lines on big screens.
Difference from MIME Base64: MIME Base64 (RFC 2045) wraps strictly at 76 characters per line, which is a protocol-level requirement. This tool is more flexible, supporting 64/76/80/100 character widths with 0/2/4-space indents for any document scenario. The 76-character option reproduces MIME wrapping exactly.
Safety of formatting: the tool only inserts line breaks and indents at the display layer and NEVER modifies the original Base64 bytes. After removing all whitespace, the formatted output is byte-identical to the original. Most Base64 decoders automatically ignore whitespace, so the formatted string can be decoded as-is.
Use Cases
- Wrap ultra-long Base64 strings to a chosen width for easier reading and screenshots
- Format Base64 for technical documentation, support tickets, or email display
- Improve Base64 layout for printing or long-term archival
- Combine with split and merge tools for Base64 structure changes
- Wrap Base64 at 76 characters per line for MIME email attachments
- Show Base64 across multiple lines during code review to spot stray characters
- Embed Base64 in Markdown with 4-space indents to match code style
- Display long Base64 payloads across lines on monitoring dashboards
How to Use
- Paste your Base64 string (with or without existing line breaks)
- Pick a line width: 64 / 76 / 80 / 100 characters
- Pick an indent: 0 / 2 / 4 spaces
- The tool re-formats in real time with your selected width and indent
- Copy the formatted output, or hit Unformat to restore a single-line string
Features
- Custom line width: pick 64 / 76 / 80 / 100 characters per line to fit any layout
- Configurable indent: choose 0 / 2 / 4 spaces for clean alignment in code blocks or Markdown
- Display-only: only adjusts the visual layout - the original Base64 data is never modified
- Real-time format: 200ms debounced re-rendering, no lag as you type
- One-click unformat: strip all line breaks and indents back to a single-line string
- Live counters: shows input character count and total output line count in real time
- One-click copy: copy the formatted output to the clipboard for docs or tickets
- 100% browser-side: every operation runs locally - your Base64 is never uploaded
Code Examples
JavaScript: Manually Implement Base64 Formatting (Understand the Logic)
javascriptUnderstand the underlying logic of Base64 formatting - split by character width and insert line breaks.
// Base64 formatting function (same logic as this tool)
function formatBase64(input, lineLength = 76, indent = 0) {
// 1. Strip all whitespace
const clean = input.replace(/\s/g, '');
if (!clean) return '';
// 2. Split by chosen width
const lines = [];
for (let i = 0; i < clean.length; i += lineLength) {
const line = clean.slice(i, i + lineLength);
lines.push(' '.repeat(indent) + line);
}
// 3. Join with line breaks
return lines.join('\n');
}
// Usage example
const b64 = 'a'.repeat(200);
console.log(formatBase64(b64, 76, 0));
// Output: Base64 with 76 characters per line
// Unformat (for decoding or transmission)
function unformatBase64(input) {
return input.replace(/\s/g, '');
}
console.log(unformatBase64(formatBase64(b64, 76, 0)).length); // 200Python: Base64 Formatting + MIME Line Wrap
pythonPython implementation that wraps at 76 characters (MIME standard) and supports custom indents.
import textwrap
def format_base64(b64_str: str, width: int = 76, indent: int = 0) -> str:
"""Format a Base64 string into multiple lines"""
# Strip all whitespace
clean = ''.join(b64_str.split())
if not clean:
return ''
# Use textwrap to split by width
lines = textwrap.wrap(clean, width=width)
# Add indent
if indent > 0:
lines = [' ' * indent + line for line in lines]
return '\n'.join(lines)
# Usage example
b64 = 'aGVsbG8gd29ybGQ=' * 10
print(format_base64(b64, 76, 0))
# Reproduce MIME Base64 (RFC 2045)
mime_format = format_base64(b64, 76)
print(f'MIME Base64 line count: {len(mime_format.splitlines())}')
# Restore to single line
single_line = b64.replace('\n', '').replace(' ', '')
print(f'Single-line length: {len(single_line)}')Command Line: fold + MIME Base64 Line Wrapping
bashThe fold utility bundled with Linux/macOS can quickly format Base64 from the command line.
# 1. Input Base64 -> wrap at 76 characters (MIME standard)
echo "aGVsbG8gd29ybGQ=" | base64 | base64 | fold -w 76
# 2. Format a long Base64 file -> write to a new file
fold -w 76 encoded.txt > formatted.txt
# 3. Wrap at 64 characters (compact display)
fold -w 64 encoded.txt > compact.txt
# 4. Strip all line breaks at once (unformat)
tr -d '\n' < formatted.txt > single-line.txt
# 5. Verify: Base64 length + line count
wc -c encoded.txt | awk '{print "Characters:", $1}'
wc -l formatted.txt | awk '{print "Lines:", $1}'
# 6. Combine with openssl for full base64 encoding + formatting
echo "Hello World" | openssl base64 -A | fold -w 76 > hello.b64.txt
cat hello.b64.txtFAQ
Does formatting change the actual Base64 content?
No. Formatting only inserts line breaks and indent spaces at the display layer - the encoding itself is untouched. Removing all whitespace from the formatted output restores the original single-line Base64 exactly. All mainstream Base64 decoders (browser-native atob / Node.js Buffer / Python base64) ignore whitespace, so the formatted string can be decoded as-is.
How is Base64 formatting different from MIME Base64?
MIME Base64 strictly wraps at 76 characters per line as defined by RFC 2045 and is the standard for email attachments. This tool is more flexible - it allows 64/76/80/100-character widths plus 0/2/4-space indents, which suits documents, screenshots and other display needs. Choosing 76 characters reproduces MIME wrapping exactly.
Is it suitable for log viewing and ticket records?
Absolutely. Long Base64 strings in ticketing systems (Jira / Zendesk), chat tools (Slack / Teams) or Markdown documents tend to overflow horizontally. The formatted multi-line display is clean and easy to read, and can be pasted directly into ticket attachments or chat windows.
Can the formatted output be decoded directly?
Yes. All mainstream Base64 decoders automatically ignore line breaks and spaces. If you ever hit an issue (e.g. older OpenSSL versions), just click Unformat to strip the line breaks before decoding.
Why are there four line widths (64 / 76 / 80 / 100)?
64 characters fits compact docs (CLI terminals, Markdown tables); 76 is the MIME email standard; 80 is the classic terminal width; 100 suits wide-screen editors and modern documents. Each width has its own best-fit scenario.
What is the indent option for?
The indent (0/2/4 spaces) keeps Base64 aligned inside code blocks or Markdown. 0 spaces suits plain text, 2 spaces matches JS / Python style, and 4 spaces fits Markdown nested code blocks.
Does formatting add extra characters to Base64?
It adds roughly 1-3% (line breaks + indent spaces), but decoding is unaffected. If size matters (e.g. URL parameters), use Unformat to restore a single-line string before transport.
Does it support UTF-8 / non-ASCII characters?
This tool does not handle character sets directly - it only formats the Base64 string itself. If your Base64 represents UTF-8 encoded text (e.g. Chinese), formatting will not affect the underlying encoding.
Is it suitable for formatting very large Base64 strings?
Yes. Formatting is real-time, and the browser handles Base64 strings under 1 MB with no issues. Strings over 10 MB may cause UI lag - in that case, process them in chunks.
The formatted output is larger - can it be compressed?
Formatting only adds line breaks and indents, which compress extremely well. You can use gzip / Brotli, or use the Base64 Stats tool to inspect the exact size increase.
Troubleshooting
Some Base64 characters are missing after formatting
The source Base64 may contain illegal characters (e.g. unhandled line breaks). Clean it with the Base64 Clean tool first, then format.
Formatted output does not match the original bytes
This should never happen - formatting only inserts whitespace and never modifies the byte content. If you see a mismatch, the source Base64 was likely corrupted (e.g. it was formatted twice, causing duplicate whitespace).
The interface lags when formatting long strings
Strings over 10 MB can make the browser sluggish. Try: (1) process in chunks; (2) use base64-clean to remove extra whitespace first; (3) reduce the line width (e.g. 64 chars) to lower per-line rendering cost.
Glossary
- Base64 formatting
- Splitting a Base64 string into multiple lines of a chosen width at the display layer. Affects only visual presentation, not the encoding itself.
- MIME Base64
- The 76-character-wrapped Base64 variant defined in RFC 2045, used primarily for email attachment transmission.
- Line length
- The number of Base64 characters per line. Common values: 64 (compact), 76 (MIME standard), 80 (classic print), 100 (wide).
- Indent
- Spaces inserted at the start of each line. Common values: 0 (none), 2 (code style), 4 (Markdown code block).
- Whitespace
- Spaces, tabs and line breaks that may appear in a Base64 string. Formatting first strips all whitespace, then re-inserts breaks at the chosen width.
- Unformat
- The reverse operation: restore a formatted (multi-line + indented) Base64 string to a single-line, whitespace-free form for decoding or transmission.
Comparison of Four Line Widths
Different line widths suit different display scenarios. Choose based on the target environment.
| Line Width | Typical Scenario | Standard | Best For |
|---|---|---|---|
64 chars | CLI terminals, Markdown tables | Compact display | Small screens / high density |
76 chars | Email attachment transmission | RFC 2045 MIME | Email / SMTP |
80 chars | Classic terminal printing | Traditional Unix terminal | Document printing |
100 chars | Modern editors / wide screens | Modern UI guidelines | IDE / documentation |
Comparison of Three Indent Styles
Different indent styles match different code conventions. Choose based on team or project habits.
| Indent | Code Style | Example (Base64 line 1) |
|---|---|---|
0 spaces | No indent (plain text) | QUJD... |
2 spaces | JS / Python convention | QUJD... |
4 spaces | Markdown nesting / Java convention | QUJD... |
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