Skip to content
ENID
Developer

Base64 vs Encryption: Why Base64 Is Not Security

Base64 encodes data; it does not protect it. Learn the difference between encoding, encryption, and hashing, and where Base64 is actually used.

Published 3 min read

The short answer

Base64 is an encoding: a reversible way to write bytes as text. It uses no key and hides nothing. Anyone can decode Base64 in a second, so it must never be used to protect a password, token, or personal data.

Encoding, encryption, hashing

PurposeReversible?Needs a key?Example
EncodingMake data fit a formatYesNoBase64, URL encoding
EncryptionKeep data secretYes, with the keyYesAES, RSA
HashingFingerprint data or store passwordsNoNo (a salt is used for passwords)SHA-256, bcrypt

If you need secrecy, use encryption. If you need to check integrity or store a password, use a hash with the right algorithm. If you need to put binary data inside text, use Base64.

How Base64 works

Base64 takes three bytes (24 bits) and writes them as four characters from a 64-character alphabet: A to Z, a to z, 0 to 9, +, and /. When the input is not a multiple of three bytes, = padding completes the last group. That is why encoded data is about 33 percent larger.

Text:    Hello, SigapTek!
Base64:  SGVsbG8sIFNpZ2FwVGVrIQ==

URL-safe Base64

+ and / have special meaning in URLs. The URL-safe variant uses - and _ instead and often drops the padding. JWTs use this form.

Where Base64 is really used

  • Email attachments (MIME), which were designed for text only.
  • Data URIs, to embed a small image directly in HTML or CSS.
  • JWT parts and other tokens.
  • HTTP Basic authentication, where user:password is Base64 encoded. This is only a format, not protection, so it is safe only over HTTPS.
  • Embedding binary in JSON or XML.

Common mistakes

  • Believing it hides data. Encoded secrets in source code or config are plain text in disguise.
  • Mixing alphabets. Standard and URL-safe Base64 are not interchangeable.
  • Forgetting UTF-8. Text must be converted to bytes with a known encoding before encoding. Non-Latin characters and emoji break otherwise.
  • Decoding binary as text. Decoding an image as text produces garbage.

Trying it

The Base64 Encoder & Decoder encodes and decodes UTF-8 text, supports URL-safe output, and tells you when the input is not valid Base64. It runs in your browser. To see Base64 inside a token, try the JWT Decoder and read what a JWT is.

FAQ

Is Base64 secure if the data is also compressed?

No. Compression and Base64 are both reversible without a key.

Why do I see == at the end?

It is padding that completes the final group of bytes.

What should I use to protect data?

Use a vetted encryption library and keep keys out of the code. Send data over HTTPS.

Related guides

Enter to open, Esc to close

Scroll to Top