Home·Terminal commands

base64

Text processing

Usage

base64 [file]

Turns bytes into ASCII text and back so binary can travel through text-only channels; it is encoding, not encryption, and the decode flag is -d on GNU but -D on older macOS.

Common flags

FlagMeaning
-dDecode. GNU and recent macOS take -d; older macOS needs -D
-wGNU: wrap at N columns, and -w0 keeps it on one line
-iGNU: ignore junk while decoding. On macOS -i names the input file
-oBSD and macOS: write to this file
-bBSD and macOS: wrap the encoded output at N characters

Examples

base64 -w0 cert.pem

One long line, no wrapping (GNU).

echo aGVsbG8= | base64 -d

Decodes back to hello.

base64 -i photo.png -o photo.txt

Encoding into a file on macOS.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does base64 do?

Turns bytes into ASCII text and back so binary can travel through text-only channels; it is encoding, not encryption, and the decode flag is -d on GNU but -D on older macOS.

Q. How do I type it?

base64 [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man base64. This command sits under Text processing.

Related commands

man page: man base64