Base64 in Bash

How to encode and decode Base64 in Bash — with copy-paste examples and a live converter to check your output.

Most Linux and macOS systems ship a base64 command-line tool that reads from stdin or a file and encodes or decodes standard Base64.

Encode to Base64 in Bash

Bash
echo -n "Hello, World!" | base64

Decode Base64 in Bash

Bash
echo "SGVsbG8sIFdvcmxkIQ==" | base64 --decode

Notes & gotchas

Always use echo -n (or printf) to avoid encoding a trailing newline. macOS's base64 uses -D instead of --decode. If base64 isn't available, openssl base64 and openssl base64 -d work as a drop-in alternative.

Try it live

0 characters

Base64 in Bash — FAQ

How do I Base64 encode a string in Bash?+

Use the code shown above. Always use echo -n (or printf) to avoid encoding a trailing newline. macOS's base64 uses -D instead of --decode. If base64 isn't available, openssl base64 and openssl base64 -d work as a drop-in alternative.

How do I decode Base64 back to text in Bash?+

Use the decode snippet above. Base64 decoding is lossless, so you get the exact original bytes back; decode them with UTF-8 to recover text.

Is Base64 encoding the same across programming languages?+

Yes. Base64 is a standard (RFC 4648), so a string encoded in one language decodes correctly in any other. Only the API differs, not the output.

Does Base64 secure my data?+

No. Base64 is an encoding, not encryption — anyone can decode it. Never use it to protect secrets.