What Base64 is for
Many formats can carry only text: JSON, XML, HTTP headers, email, environment variables. Base64 (RFC 4648) lets them carry arbitrary bytes by writing every 3 bytes as 4 characters from a 64-character alphabet: A to Z, a to z, 0 to 9, + and /, with = as padding at the end.
In identity work you meet Base64 constantly. PEM keys and certificates are Base64 between header lines. SAML messages are Base64. HTTP Basic authentication sends a client id and secret as Base64. Kubernetes secrets store values as Base64.
How encoding and decoding work
The encoder reads the input three bytes (24 bits) at a time and writes four 6-bit characters. If the last group has one or two bytes, it writes two or three characters and pads with = so the length is a multiple of four.
"client:secret" → Y2xpZW50OnNlY3JldA==
"ab" → YWI=
"abc" → YWJjThe decoder reverses the steps. It ignores line breaks, which some formats insert every 64 or 76 characters, and uses the padding to know how many bytes the last group holds.
Text needs an encoding first
Base64 works on bytes, not characters. Text must first become bytes, and the right choice is almost always UTF-8. This tool encodes text as UTF-8, so characters such as é or ö survive the round trip.
What this tool does
- Encodes text (UTF-8), hex bytes, or a file of up to 1 MB to Base64.
- Decodes Base64 to text, and always to hex, with JSON shown formatted.
- Adds or removes
=padding. - Wraps output at 76 characters per line, the MIME convention, when you ask.
- Warns when input uses
-and_, which means it is Base64url, and decodes it anyway.
Files are read in your browser with the File API and never uploaded.
Step by step
- Choose Encode or Decode.
- To encode, type text, paste hex bytes, or pick a file.
- Choose padding and line wrapping if the target format needs them.
- Copy the result, or press the button to use it as input and go the other way.
Base64 in Keycloak and OAuth
HTTP Basic client authentication
A confidential client can authenticate at Keycloak’s token endpoint with client_secret_basic: the header Authorization: Basic followed by the Base64 of client_id:client_secret. RFC 6749 says the id and secret should be form-encoded before joining, which matters only if they contain special characters. The client authentication header tool builds the header for you.
printf '%s' 'web-app:sample-secret' | base64
# d2ViLWFwcDpzYW1wbGUtc2VjcmV0PEM keys and certificates
The lines between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- are Base64 of the DER bytes. The x5c member in a realm’s JWKS holds the same certificate as standard Base64 without line breaks.
SAML
SAML responses posted to a service provider are Base64-encoded XML. Requests sent by redirect are deflated first, then Base64-encoded, then URL-encoded. The SAML response decoder handles all of that.
Kubernetes secrets
Values in a Kubernetes Secret’s data field are Base64. When Keycloak runs on Kubernetes, database passwords and admin credentials often sit in such secrets. Decoding them shows their value; encoding is not protection.
Use cases
- Building a Basic authentication header for a quick
curltest. - Reading what is inside an environment variable or secret that looks like Base64.
- Turning a small file, such as a certificate or an icon, into text for a configuration field.
- Checking whether two encoded values hold the same bytes, by comparing their hex.
Common problems
| Problem | Cause and fix |
|---|---|
| Decoded text shows strange characters | The bytes are not UTF-8 text; read the hex instead |
| A trailing newline in the encoded secret | echo adds one; use printf or echo -n |
| “is not a Base64 character” | A stray quote, comma or other character from copying |
| Padding is missing | Some systems strip it; the tool adds it back for decoding |
| Uses - and _ | It is Base64url; it still decodes |
The trailing-newline mistake is the most common one with Basic authentication: echo "id:secret" | base64 encodes a newline as part of the secret, and the server rejects it.
Base64 on the command line
Most systems already have a Base64 tool. Knowing the commands helps when you script a test or work on a server without a browser.
# encode text without a trailing newline
printf '%s' 'web-app:sample-secret' | base64
# decode (GNU coreutils uses -d, macOS accepts -d or -D)
printf '%s' 'd2ViLWFwcDpzYW1wbGUtc2VjcmV0' | base64 -d
# encode a file on one line (GNU coreutils wraps at 76 by default)
base64 -w 0 cert.derGNU base64 wraps output at 76 characters unless you pass -w 0. If a value you encoded on Linux has line breaks in it, that is why. The wrap option in this tool reproduces the same layout when a format needs it.
Variants you may meet
RFC 4648 defines one standard alphabet, but several conventions sit on top of it. Knowing which one a system expects avoids most decoding surprises.
| Variant | Alphabet | Padding | Line breaks | Seen in |
|---|---|---|---|---|
| Standard Base64 | + and / | Yes | No | JSON values, HTTP Basic, x5c |
| MIME | + and / | Yes | Every 76 characters | Email, some older tools |
| PEM | + and / | Yes | Every 64 characters | Keys and certificates |
| Base64url | - and _ | Usually no | No | JWTs, PKCE, JWK members |
Decoders that are strict about line length or padding reject values from the other variants. This tool is lenient on input: it ignores whitespace, restores missing padding, and accepts - and _ with a note.
Checking a value step by step
When a service rejects a Base64 value, work through these checks in order.
- Decode the value here and look at the hex. Trailing
0ameans a newline was encoded; trailing0d 0ameans a Windows line ending. - Check whether the system wants standard Base64 or Base64url, and whether it wants padding.
- Check the text encoding. If the decoded text shows odd characters, the original may not have been UTF-8.
- Encode the exact intended value again with padding and no line breaks, and compare.
If a system rejects a value you encoded here, decode its expected example with this tool and compare the hex of both. A difference in the last bytes usually means a newline or different padding; a difference throughout means a different text encoding or variant.
When Base64 is the wrong tool
Base64 solves one problem: moving bytes through a channel that only carries text. People sometimes reach for it for other jobs, where it does harm.
- Hiding secrets: Base64 hides nothing. Use encryption, or keep the secret out of the file.
- Shortening data: Base64 makes data a third larger. Compress first if size matters.
- URLs and file names:
+,/and=need escaping there. Use Base64url instead. - Comparing values: two encodings of the same bytes can differ in padding or line breaks. Decode both and compare the bytes.
Security notes
Base64 is an encoding, not encryption. Anyone can decode it in a second. A client secret in a Basic header is protected only by TLS, and a Base64 value in a configuration file is as readable as plain text.
This page runs entirely in your browser and sends nothing to us. Still, prefer test values over production secrets.
If you find a secret stored as Base64 in a place you did not expect, treat it as exposed.
Best practices
- Use UTF-8 for text before encoding.
- Use Base64url instead of Base64 for anything that goes in a URL or a JWT.
- Never treat Base64 as a way to hide data.
- Use
printfrather thanechowhen encoding secrets on the command line.