1001Ferramentas
๐Ÿ” Converters

Base64: What It Is, What It's For, and When NOT to Use It

The problem Base64 solves, how 3 bytes become 4 characters, legitimate uses like data URLs, and the myth that Base64 "encrypts".

Updated on June 30, 2026 ยท 6 min read

The problem Base64 solves

Much of the internet's plumbing was built to carry text, not raw binary. The email protocol (SMTP) was designed in 1982 to move only 7-bit ASCII characters. URLs allow a narrow set of characters. Formats like JSON and XML are, ultimately, text files. A binary file โ€” a photo, a PDF, a cryptographic key โ€” is a stream of bytes ranging from 0 to 255, and many of those values are invisible control characters (newlines, null bytes, tabs) that these channels misread or quietly drop.

Base64 is the bridge. It takes any sequence of bytes and rewrites it using just 64 safe characters โ€” uppercase letters, lowercase letters, digits, and two symbols โ€” that survive intact through any text channel. That is where the name comes from: an encoding in base 64. It is not compression and not encryption; it is a way to repackage binary as plain text so it can pass through systems that only understand text.

The standard alphabet has 65 symbols in total: the 26 uppercase letters Aโ€“Z (indices 0โ€“25), the 26 lowercase aโ€“z (26โ€“51), the digits 0โ€“9 (52โ€“61), + (62) and / (63). The equals sign = carries no data โ€” it only pads the end.

How the encoding works (3 bytes become 4 characters)

The trick is bit arithmetic. A byte is 8 bits; Base64 regroups those bits into chunks of 6. The least common multiple of 8 and 6 is 24, so the unit of work is 3 bytes = 24 bits, which split into 4 groups of 6 bits. Each 6-bit group is a number from 0 to 63 โ€” exactly one index into the alphabet. That is why the ratio is always 3 in, 4 out.

Let's encode the word Man by hand. First, the ASCII codes in binary:

CharacterDecimalBinary (8 bits)
M7701001101
a9701100001
n11001101110

Stitch the 24 bits together and slice into four 6-bit pieces:

010011 | 010110 | 000101 | 101110

6 bitsValueCharacter
01001119T
01011022W
0001015F
10111046u

Result: Man becomes TWFu. Three readable bytes, four output characters. You can check any string like this in the Base64 Converter, which encodes and decodes both ways.

What if it isn't a clean 3 bytes?

Not every input is a multiple of 3 bytes long. That is where = padding comes in. The rule is simple:

  • 2 leftover bytes โ†’ produce 3 characters + one =. E.g. Ma โ†’ TWE=
  • 1 leftover byte โ†’ produces 2 characters + two ==. E.g. M โ†’ TQ==
  • no leftover โ†’ no = at all

The = tells the decoder how many trailing bits were just filler and should be discarded. This is why a valid Base64 string is always a multiple of 4 characters long โ€” padding included.

Legitimate uses: data URLs, email and tokens

Base64 is no academic curiosity; it shows up everywhere binary needs to travel through a text-only channel.

Data URLs. You can embed an image straight into your HTML or CSS with an address like data:image/png;base64,iVBORw0KGgo.... The browser decodes it and draws it without making another request. That is handy for tiny icons and HTML emails, where every extra request adds latency. To generate that snippet from a file, use the Image to Base64 tool; and to turn a data URL back into a viewable file, Base64 to Image runs the reverse path.

Email attachments. Every time you send a PDF, it travels Base64-encoded inside the message's MIME body. The MIME standard even inserts a line break every 76 characters so it doesn't trip old line-length limits.

Tokens and URLs. There is a variant called Base64URL, used in JWTs and in links: it swaps + for - and / for _, because those two symbols have special meaning in web addresses, and it usually drops the padding. Same idea, with a URL-proof alphabet.

The myth that Base64 encrypts

This is the dangerous misunderstanding. Base64 hides nothing. There is no key, no secret, no password. The transformation is fully reversible by anyone who knows the algorithm โ€” and the algorithm is public, implemented in every programming language. Seeing cGFzc3dvcmQ= in a config file and thinking it is protected is like writing a password backwards and calling it secure: it takes seconds to reverse.

The essential difference:

Base64 (encoding)Encryption
Needs a key?NoYes
GoalSafe transport over text channelsConfidentiality
Who can reverse it?AnyoneOnly the key holder

If you need to protect a secret, use real encryption (AES, for example) or a password-hashing algorithm like bcrypt. Base64 is only the wrapping paper. If your question is merely whether a string is valid Base64 โ€” multiple-of-4 length, only alphabet characters, correct padding โ€” the Base64 Validator runs that check before you even try to decode it.

The cost of the 33% size overhead

Packing binary into text has a price. Since every 3 bytes become 4 characters, and each character takes 1 byte as text, the output ends up 4/3 larger than the input โ€” roughly 33% bigger. A 300 KB image becomes about 400 KB of text. In MIME email, with a line break every 76 characters, the overhead climbs past 36%.

That cost is irrelevant for a 1 KB icon, but it becomes a real problem when the technique is abused. Embedding a large photo as a data URL in your CSS, for instance, is almost always a bad idea:

  • The file grows by a third and stays inside the HTML/CSS, where the browser can't cache it separately.
  • The browser can't download the image in parallel โ€” it blocks the page from rendering.
  • Base64 text doesn't compress as well with gzip as the original binary would.

The rule of thumb: use Base64 when the channel requires text (email, a small data URL, a token, a JSON field). For large files the browser can fetch on its own, serve the raw binary from a normal URL and let caching do its job.

Frequently asked questions

Is Base64 safe for storing passwords?

No. Base64 is reversible by anyone, with no key at all. Storing a password Base64-encoded is the same as storing it in plain text. For passwords, use a slow, salted hashing algorithm such as bcrypt or Argon2.

Why do some Base64 strings end with = or ==?

Those are padding characters. They appear when the original data isn't a multiple of 3 bytes long: one leftover byte produces ==, and two leftover bytes produce =. They keep the output a multiple of 4 characters and tell the decoder how much to discard at the end.

What's the difference between Base64 and Base64URL?

It's the same encoding, but Base64URL replaces the two characters that cause trouble in web addresses โ€” + with - and / with _ โ€” and usually omits the = padding. It's the variant used in JWT tokens and in any data that must travel inside a URL.

Does Base64 make a file smaller?

The opposite: it makes it about 33% larger. Base64 is not compression; it's just a way to represent bytes as text. If you want to reduce size, you need compression (gzip, Brotli) โ€” a completely different process.

How do I know a string is valid Base64?

A standard Base64 string uses only Aโ€“Z, aโ€“z, 0โ€“9, + and /, has a length that is a multiple of 4 (counting padding), and any = can only appear at the end. To check without decoding by hand, run the string through the Base64 Validator.

Tools mentioned in this guide

Keep reading