Base64 on the command line

Published

In this guide

This developer guide on Base64Encoding explains bash in plain language for developers and everyday users.

Everything important stays private: try the matching converter or tool in your browser — files and tokens are not uploaded.

Read the full English article below for code samples and edge cases, or switch language anytime from the menu. We keep expanding translations from real user feedback.

Try these private tools next

Linux (GNU coreutils)

echo -n 'Hello' | base64          # SGVsbG8=
echo 'SGVsbG8=' | base64 -d       # Hello
base64 -w0 image.png > image.b64  # no line wrapping
base64 -d image.b64 > image.png

Always use echo -n (or printf). Plain echo appends a newline, so echo 'Hello' | base64 gives SGVsbG8K, the encoding of Hello\n.

By default GNU base64 wraps output at 76 characters. Use -w0 to get a single line, which is what you want for JSON, environment variables and HTTP headers.

Decode ignores newlines but fails on other junk unless you add -i (--ignore-garbage).

macOS (BSD)

base64 -i image.png -o image.b64   # encode, no wrapping by default
base64 -D -i image.b64 -o image.png
pbpaste | base64 -D                # decode the clipboard

Newer macOS versions accept -d as well.

OpenSSL (works everywhere)

openssl base64 -A -in file.bin -out file.b64   # -A = single line
openssl base64 -d -A -in file.b64 -out file.bin

Without -A, OpenSSL wraps at 64 characters and, when decoding, expects lines of at most 64 characters.

Windows

# PowerShell
[Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\img.png"))
[IO.File]::WriteAllBytes("C:\out.png", [Convert]::FromBase64String($b64))

# cmd.exe
certutil -encode in.bin out.b64   # adds BEGIN/END CERTIFICATE lines
certutil -decode out.b64 in.bin

Useful one-liners

# Basic auth header
printf '%s' 'user:pass' | base64

# Kubernetes secret values
kubectl get secret my-secret -o jsonpath='{.data.password}' | base64 -d

# Data URI for an image
echo "data:$(file -b --mime-type logo.png);base64,$(base64 -w0 logo.png)"

# Decode Base64URL (JWT payload)
cut -d. -f2 <<<"$JWT" | tr '_-' '/+' | base64 -d 2>/dev/null

The last command may complain about missing padding; the JWT decoder handles that for you.

Ofte stillede spørgsmål

Does this page upload my data?

No. Articles are static. Linked tools run locally in your browser unless a feature explicitly needs a network relay.

Can I request a translation or a new tool?

Yes — use the private feedback form. We prioritize what users ask for across languages.

What is the fastest way to try bash?

Open the homepage Base64 converter or the related tools linked on this page and paste a sample.

Relaterede værktøjer og guider

Kommentarer (0)

Spørgsmål, ideer eller en fejl i “Base64 on the command line”? Skriv en kommentar, bedøm værktøjet, eller svar på andre.

Ingen kommentarer endnu. Vær den første til at dele din feedback!

Skriv en kommentar

Bedøm dette værktøj:
Esc
↑ ↓ flyt↵ åbnEsc luk