base64: invalid input on Mac: causes and fixes
Fix "base64: invalid input" on a Mac: strip whitespace, convert URL-safe Base64, fix padding, or decode pasted text in Bytepliers with no cleanup.
Updated 5 min read
On this page
You pasted some Base64 into Terminal, ran a decode, and got this:
base64: invalid inputThe text looked fine. It usually is fine. The macOS decoder is just stricter than the text you gave it.
Why it happens
Causes, most common first:
- Whitespace or line breaks. Text wrapped by an email client, a terminal, a PEM-style file or a Windows machine carries
\nor\r\ncharacters the decoder does not expect. - URL-safe alphabet. The string uses
-and_instead of+and/, and often has no=padding. JWT segments look like this. - Wrong padding. The length is not a multiple of 4 because
=characters were dropped. - Text around the Base64. A
data:image/png;base64,prefix, quotes, a label, or a trailing prompt character copied along with it. - An incomplete paste. A terminal, chat app or line limit cut the string short.
The macOS base64 is the BSD version. Its man pages (as of November 2026) describe raw RFC 4648 input, and the mirrors we checked list different options for different macOS versions. Run man base64 on your Mac before relying on any flag beyond -d.
Step-by-step fixes
Fix 1: strip whitespace and line breaks
Symptom: the text came from an email, a wrapped terminal, a file with line breaks, or a Windows machine.
- Copy the Base64 text.
- Run:
pbpaste | tr -d '[:space:]' | base64 -dpbpaste prints your clipboard, tr -d '[:space:]' deletes every space, tab and line break, and base64 -d decodes what is left. Nothing here changes a setting, so there is nothing to undo.
If the text is in a file instead:
tr -d '[:space:]' < encoded.txt | base64 -dTo save binary output to a file, add -o:
tr -d '[:space:]' < encoded.txt | base64 -d -o decoded.binFix 2: convert URL-safe Base64
Symptom: the string contains - or _, and may end without =.
- Translate the characters back:
pbpaste | tr -d '[:space:]' | tr '_-' '/+' | base64 -d- If it still fails, count the characters. Standard Base64 length is a multiple of 4. If 2 characters are left over, add
==at the end. If 3 are left over, add=. If 1 is left over, the paste is incomplete (Fix 4).
Fix 3: remove text around the Base64
Symptom: the string starts with data:image/png;base64,, sits inside quotes, or has a label in front.
- Delete everything that is not the Base64 itself.
- Run the decode again.
For an image data URI, skip the cleanup: the Base64 Image tool in Bytepliers accepts the whole data: URI.
Fix 4: re-copy an incomplete paste
Symptom: trailing characters are missing, or the text was cut off by a terminal, chat app or line limit.
Copy the source again. No flag can recover bytes that were never pasted.
Quick reference
| Cause | Symptom | Fix |
|---|---|---|
| Line breaks or spaces | Wrapped or emailed text | tr -d '[:space:]' before base64 -d |
| URL-safe alphabet | - and _, no = | tr '_-' '/+', then add = padding |
| Wrong padding | Length not a multiple of 4 | Add = or == |
| Prefix or quotes | data:...;base64, in front | Delete the extra text |
| Cut-off paste | Missing tail | Copy the source again |
Decode it in Bytepliers instead
The Base64 tool in Bytepliers accepts both Base64 alphabets, whitespace and missing padding when decoding. You do not need to work out which problem you have.
- Open Bytepliers and press ⌘2 (Command-2) to open Base64. You can also pick it in the Encode group of the sidebar.
- Switch the mode to Decode.
- Click Paste from Clipboard in the input pane, or press ⌘V.
- Read the result in the output pane. Copy it with ⇧⌘C (Shift-Command-C).
Other ways in, without opening the main window:
- Quick Panel: copy the text, press ⌥⌘B, and type
b64dto pick Base64 Decode (it is also in the Transform menu). Press ⏎ to copy the result. See Quick Panel, Instant Replace and the menu bar. - Clipboard detection: press ⇧⌘K (Check Clipboard) and Bytepliers can suggest the Base64 tool when the clipboard looks like Base64. Automatic suggestions when you switch to the app are off by default; you turn them on with Clipboard matches in Settings. See Clipboard detection in Bytepliers.
Related tools in the same window: Base64 Image previews a Base64 or data: URI image, and GZIP decompresses Base64 or hex that holds gzip, zlib or raw DEFLATE data. For a JWT, the JWT Decoder reads the whole token.
Checklist before you try again
- The string has no spaces, tabs or line breaks.
- It contains only letters, digits,
+,/and=(or-and_if you convert them). - The length is a multiple of 4 after padding.
- No
data:prefix, quotes or labels remain. - The source text was copied in full.
If nothing works
If the string still fails after cleanup, the data may not be Base64 at all, or it may be corrupted. Ask whoever produced it, or the vendor of the tool that generated it, to confirm the encoding. Include:
- The exact error text:
base64: invalid input - Your macOS version and the output of
man base64 | head -20 - The first and last 20 characters of the string, and its length
- What you already tried
Decoding a Base64 string on macOS fails with "base64: invalid input".
I removed whitespace with tr -d '[:space:]' and tried converting - and _ to + and /.
The string is N characters long and starts with XXXX and ends with YYYY.
Can you confirm which Base64 variant and padding rules it uses, and whether it is complete?Common questions
Does base64 -di work on a Mac?
Not as it does on Linux. On GNU coreutils -i ignores garbage characters. In the macOS man pages we checked, -i names an input file. Use tr -d '[:space:]' instead.
Why does the same string decode on Linux but not on my Mac?
GNU base64 can skip unexpected characters with -i and is more forgiving of wrapped lines. The macOS decoder expects raw Base64, so cleanup is needed.
Do I need the = padding?
The Terminal decoder wants correct padding, so add = or == when the length is off. The Base64 tool in Bytepliers accepts missing padding.
Is it safe to paste a token or secret into an app?
Bytepliers works offline and does not send input anywhere. It also marks secrets it copies out as concealed, so clipboard managers that honor the convention do not store them.
Bytepliers is part of MacSuite, and each app has a 7-day trial on each Mac. Details are on the pricing page.