What Is Base64 Encoding and When Should You Use It?

If you have looked inside an email's source, a JSON API response or a web page's code, you may have seen long strings like SGVsbG8= or iVBORw0KGgo…. That is Base64. So what is Base64 encoding, why do developers use it everywhere, and what should you never use it for? Here is a clear explanation with examples.

Screenshot of the Base64 Encode and Decode on Assen Tools
The Base64 Encode and Decode in use. Open the Base64 Encode and Decode – free, no sign-up.

The problem Base64 solves

Many systems were designed to carry text, not raw binary data such as images, PDFs or encryption keys. Email, JSON, XML, URLs and HTML attributes can corrupt or reject arbitrary bytes. Base64 converts any data into a limited set of safe, printable characters so it can travel through text-only channels intact.

How it works

Base64 uses 64 characters: A–Z, a–z, 0–9, plus + and /, with = used as padding.

  1. Take the data three bytes (24 bits) at a time.
  2. Split those 24 bits into four groups of 6 bits.
  3. Map each 6-bit value (0–63) to one of the 64 characters.
  4. If the data does not divide evenly into three bytes, add = padding at the end.

Examples:

  • "Hi" → SGk=
  • "Hello" → SGVsbG8=
  • "Assen Tools" → QXNzZW4gVG9vbHM=

To reverse it, you simply base64 decode the text back into the original bytes.

Base64 makes data bigger

Because every 3 bytes become 4 characters, Base64 output is about 33% larger than the original. A 300 KB image becomes roughly 400 KB of text. That is the price of making it safe to transport.

Base64 is not encryption

This is the most important point. Anyone can decode Base64 instantly – it hides nothing. Never use it to "protect" passwords, API keys or personal data. If you need secrecy, use real encryption; if you need to store passwords, use proper password hashing (see what is a hash function).

Where Base64 is used

  • Email attachments: the MIME standard encodes attachments as Base64.
  • Data URIs: small images embedded directly in HTML or CSS – see how to embed an image in HTML with Base64.
  • JSON Web Tokens: the header and payload are Base64URL-encoded – see what is a JWT.
  • APIs: sending files or binary data inside JSON.
  • Basic authentication headers: username:password is Base64-encoded (which is why it must always be used over HTTPS).

Base64URL: the URL-safe variant

Standard Base64 uses + and /, which have special meanings in URLs. Base64URL replaces them with - and _ and often drops the = padding. JWTs use this variant.

Encode and decode instantly

The free Base64 Encode and Decode tool converts text to Base64 and back, with full Unicode support, right in your browser. For images, use Image to Base64 to get a ready-made data URI.

Related developer tools:

Frequently asked questions

Why does Base64 sometimes end with = or ==? Padding. One = means the last group had two bytes; == means it had one.

Is Base64 the same as hexadecimal? Both turn bytes into text, but hex uses 16 characters and doubles the size, while Base64 uses 64 characters and adds only about a third.

Can Base64 contain line breaks? Some formats, such as email, wrap Base64 at 76 characters per line. Decoders usually ignore the breaks.

Should I store images in my database as Base64? Usually not. It makes them a third larger and harder to cache. Store files on disk or in object storage and keep only the path in the database.

Summary

So, what is Base64 encoding? A way to represent any binary data using 64 safe text characters so it survives email, JSON and URLs. It makes data about a third larger and provides no security at all. Encode or decode anything in seconds with the free Base64 Encode and Decode tool.

Jonathan Nwachukwu, founder of Assen Tools

Written by

Jonathan Nwachukwu · Founder & developer

Jonathan is a freelance web developer and web development teacher who builds Laravel, WordPress and WooCommerce sites for clients. He built AssenTools to put the everyday file, photo and calculation jobs he kept doing for clients and students into one free, private toolbox, and he maintains every tool and guide on the site.