Is Base64 Encryption? What Base64 Is and When to Use It
By Marcelo Torres · Published
A Base64 string such as cGFzc3dvcmQxMjM= looks scrambled, so it's easy to assume it hides something. It doesn't. Here's what Base64 actually is, why it exists and why it should never be used to protect data.
Encoding, not encryption
Base64 is an encoding: a fixed, public rule for writing any data with 64 safe characters (A–Z, a–z, 0–9, + and /). There's no key and nothing secret, so anyone can reverse it instantly. cGFzc3dvcmQxMjM= decodes to password123, as you can check with the Base64 Encoder & Decoder.
Encryption is different: it transforms data with a secret key, and without that key the original can't be recovered in any practical amount of time. Hashing is different again: it turns data into a fixed-length fingerprint that can't be reversed, which is how well-built systems store passwords.
Why Base64 exists
Many systems were designed to carry text, not arbitrary bytes. Emails, JSON, URLs, HTML and configuration files can break if they contain raw binary data or certain special characters. Base64 solves that by representing any bytes with characters that travel safely through text-only channels.
- Email attachments (MIME) are sent as Base64.
- Small images can be embedded in HTML or CSS as data URLs.
- APIs send files, keys and signatures inside JSON as Base64 strings.
- JSON Web Tokens use URL-safe Base64 for their header and payload.
The cost: about 33% more data
Base64 writes every 3 bytes as 4 characters, so encoded data is about a third larger than the original. That's acceptable for small items, but embedding large images or files as Base64 makes pages and requests heavier. For big files, serving them separately is usually better.
Common mistakes
- Storing passwords in Base64. Anyone with access to the database can read them. Passwords must be hashed with an algorithm designed for that purpose.
- Hiding API keys or secrets in Base64 inside client code. They can be decoded by anyone who opens the browser's developer tools.
- Assuming a JSON Web Token is private. Its payload is only Base64-encoded and can be read by anyone; the signature only proves it wasn't modified.
What to use instead
To keep data confidential, use real encryption with a well-reviewed library, such as AES-GCM through the Web Crypto API or your platform's standard library. To store passwords, use a password hashing algorithm such as Argon2, scrypt or bcrypt. And for the passwords themselves, generate long random ones with the Password Generator.