Base64 vs Base64URL Explained
Published:
Base64 and Base64URL both represent bytes as text. They are useful when a protocol needs to carry binary data through a textual field. Choosing the right variant is part of following that protocol; neither variant conceals the original value.
Compare the alphabets and padding
Base64 uses letters, digits, plus and slash. Base64URL replaces plus with a hyphen and slash with an underscore. Padding uses equals signs; whether padding can be omitted depends on the surrounding specification. RFC 4648 defines the encodings. Do not assume that every decoder accepts both alphabets or every padding style.
Bytes as text Base64 Unpadded Base64URL
hello aGVsbG8= aGVsbG8
??? Pz8/ Pz8_
>>> Pj4+ Pj4-
Try the difference in the browser
- Open the Base64 encoder and decoder and enter
???. - Select Encode. The output should be
Pz8/. - Select Encode Base64URL. The output should be
Pz8_. - Replace the input with
Pz8_and choose Decode Base64URL to recover the three question marks.
FATOPS uses UTF-8 for text. For example, café encodes as Y2Fmw6k=. A binary file is not necessarily UTF-8 text, so a text decoder is not a general binary-file viewer.
A newline changes the input bytes
In a terminal, use printf to make the input explicit:
printf '%s' 'hello' | openssl base64 -A
printf '%s' 'aGVsbG8=' | openssl base64 -d -A
The first command produces aGVsbG8=. The second writes hello without a trailing newline, so a shell prompt may appear immediately after it. Encoding hello plus a newline produces aGVsbG8K instead. If two systems disagree, compare the source bytes and trailing whitespace before changing encoders.
Follow the receiving format
JWT components use Base64URL conventions, while Kubernetes Secret data fields use Base64. A query parameter may still require URL encoding depending on the protocol. Base64URL is not a substitute for encoding an entire URL correctly, and changing an alphabet does not turn arbitrary text into a JWT.
For a malformed value, check the expected variant, padding policy and whether copying introduced spaces or line breaks. Do not add padding blindly to make a corrupted value appear valid. Consult the format that produced the value when its encoding rules are unclear.
Keep encoded credentials private
Anyone with the encoded value can reverse this transformation without a key. A Base64-encoded password belongs under the same access controls as its original text. Use invented values when testing the tool or writing examples, and choose encryption or secret storage based on the actual confidentiality requirement.