Base64 encode and decode from the command line
The coreutils one-liner everyone half-remembers — plus the two forgotten flags that fix 90% of base64 surprises: `echo -n` and `-w 0`.
Run `echo -n 'text' | base64` to encode, and `echo 'aGVsbG8=' | base64 -d` to decode back.
01Command
Command
$ echo -n 'hello' | base6402What it does
Two subtle traps explain most wrong results: without `echo -n` the trailing newline gets encoded, corrupting values compared with online encoders; and GNU base64 wraps output at 76 columns by default, so pass `-w 0` when the result goes into a URL, JWT or config value. For files, `base64 image.png > image.b64` and `base64 -d image.b64 > image.png` round-trip in place. Remember that base64 is an encoding, not encryption — it provides zero confidentiality.
03Risk
04Undo
Undo
$ echo 'aGVsbG8=' | base64 -d05Sources
- base64(1) — base64 encode/decode data and print to standard outputEvidence: Documents -d decode mode, -w wrap-width (0 disables wrapping), and -i ignore-garbage input handling
Last verified: 2026-09-17 · Category: Developer