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`.

Linuxbase64coreutilscliencodingLow risk
Run `echo -n 'text' | base64` to encode, and `echo 'aGVsbG8=' | base64 -d` to decode back.

01Command

Command
$ echo -n 'hello' | base64

02What 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

RiskLow risk
RequirementsPart of GNU coreutils, preinstalled on all Linux distros

04Undo

Undo
$ echo 'aGVsbG8=' | base64 -d

05Sources

Last verified: 2026-09-17 · Category: Developer