On-device AI — professional-grade, fully private.

Documents

What Is Base64 Encoding? How It Works, Why It Is 33% Bigger, and Why It Is Not Encryption

Base64 writes any file or text as plain letters and digits for email, JSON and URLs. See how it works, why it adds 33%, and why it is not encryption.

Updated November 1, 20268 min read

Base64 is a way of writing any data, a photo, a PDF or a sentence, using only 64 safe characters: the letters A to Z and a to z, the digits 0 to 9, plus two symbols and an equals sign for padding. It exists because many systems that move data around, such as email, JSON and web addresses, were built for plain text and break when they meet raw binary. Base64 is not compression and it is not encryption. It makes data about 33% bigger, and anyone can reverse it in a second, so never use it to hide anything.

What Base64 actually does

Computers store everything as bytes, and a byte can hold any of 256 values. Some of those values are control codes or characters that text-only systems treat as special: a line break, a null byte, a quote mark. Push a JPEG through a system that expects text and it may be changed, cut short or rejected. Base64 solves this by translating every byte into a form that is guaranteed to be ordinary, printable text. The receiver translates it back and gets the exact original bytes.

Think of it as a shipping crate. The contents are unchanged, but the crate fits every conveyor belt. The price of the crate is extra volume, which is where the 33% comes from.

How 3 bytes become 4 characters

The method is small enough to do by hand. Take three bytes, which is 24 bits. Cut those 24 bits into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, and each number maps to one character in the Base64 alphabet: 0 to 25 are A to Z, 26 to 51 are a to z, 52 to 61 are 0 to 9, 62 is + and 63 is /.

Worked example with the word Man. The letters M, a and n are the bytes 77, 97 and 110, written in binary as 01001101, 01100001 and 01101110. Join them into one 24-bit string and regroup into sixes: 010011, 010110, 000101, 101110. Those are 19, 22, 5 and 46, which map to T, W, F and u. So Man becomes TWFu.

StepValue
TextM, a, n
Bytes (decimal)77, 97, 110
Bits, joined01001101 01100001 01101110
Regrouped in 6 bits010011 010110 000101 101110
Numbers19, 22, 5, 46
Base64 charactersT, W, F, u

Why the output is 33% bigger

Three bytes in, four characters out, and each character takes one byte to store. That is a ratio of 4 to 3, so the result is about one third bigger than the original. The exact length is 4 times the input size divided by 3, rounded up. A 3,000 byte file becomes 4,000 characters. A 1 MB photo becomes roughly 1.33 MB of text.

Two details change the arithmetic slightly. Email and PEM certificate formats break Base64 into lines (76 or 64 characters per line), and each line break adds a little more. And when the input is not a multiple of three bytes, padding is added, covered below.

Original sizeBase64 size (about)Extra
3 KB4 KB+1 KB
100 KB133 KB+33 KB
1 MB1.33 MB+0.33 MB
10 MB13.3 MB+3.3 MB

This is the main reason not to embed big images as Base64 on a web page. A 200 KB image costs the page about 267 KB, and the browser cannot cache it separately from the page that holds it. For small icons the saved request is worth it; for photos it rarely is. If an image is the problem, reduce its size first, then encode it.

Padding: what the equals signs are for

Real data is rarely a neat multiple of three bytes. When one or two bytes are left over, Base64 pads the final group with zero bits and adds = signs so the output is always a multiple of four characters. Two bytes left over give one =. One byte left over gives ==.

InputBytesBase64Padding
Man3TWFunone
Ma2TWE=one =
M1TQ==two ==
Hello5SGVsbG8=one =

Padding carries no data. It only tells the decoder where the real bits stop. Many systems accept Base64 without it, and tokens usually leave it out, but a strict decoder may refuse a string with the wrong length. If a decode fails with a length error, a missing = at the end is the first thing to check.

Where you meet Base64 every day

  • Data URIs. A string beginning data:image/png;base64, followed by the encoded picture lets an image live inside HTML, CSS or an email signature with no separate file.
  • Email attachments. Email was designed for 7-bit text, so MIME encodes attachments as Base64, wrapped at 76 characters per line. This is also why an attachment is about a third bigger on the wire than on your disk; see the Gmail attachment limit guide.
  • JSON and API payloads. JSON has no binary type, so an API that accepts an uploaded image or PDF usually asks for it as a Base64 string in a field. Format the surrounding payload with the JSON formatter to read it more easily.
  • Tokens and headers. The three parts of a JSON Web Token are Base64 strings, and HTTP Basic authentication sends username:password as Base64.
  • Certificates and keys. PEM files, the ones between BEGIN and END lines, are Base64 wrapped at 64 characters per line.

Encode or decode Base64 step by step

1

Open the tool and pick a direction

Open the Base64 encoder and decoder and choose Encode to produce Base64, or Decode to recover the original. There are also dedicated pages for encoding and decoding.

2

Paste text or drop a file

Type or paste into the box, or drop a file such as an image or PDF. Typed text converts as you type, and the panel shows input size, output size and the overhead percentage.

3

Set the format if you need to

Under Alphabet choose Standard or URL-safe. Turn on Wrap the result as a data URI if the result is going into HTML or CSS. Choose Line wrapping of 64 (PEM) or 76 (MIME) only when a certificate or mail body requires it.

4

Decode to text or to a file

When decoding, set Decoded output to Text to read the result in the box, or File to download it. The tool identifies the file type, so a decoded PNG downloads as a PNG.

5

Copy or download

Copy the result or download it. It all runs on your device, not our servers, so a private image or a key is not uploaded to be converted.

Convert text and files in both directions, with standard and URL-safe alphabets and data URI output. Free: one file up to 25 MB at a time. Pro: queue up to 100 files and download them as one ZIP. Runs on your device, not our servers.

Encode or decode Base64

URL-safe Base64

The standard alphabet uses + and /, and both cause trouble in web addresses: a plus can be read as a space in a query string, and a slash is a path separator. The URL-safe variant swaps them for - and _ and usually leaves off the = padding. This is the form used in JSON Web Tokens, in filenames and in many query parameters.

StandardURL-safe
Character 62+-
Character 63/_
Padding= keptusually dropped
Typical useEmail, PEM, data URIsTokens, filenames, query strings

When decoding, the tool detects which alphabet a string uses, so you do not have to know in advance. When encoding, choose URL-safe and the option to drop the trailing = signs. Do not confuse this with percent-encoding, where characters become codes like %20; that is a different job, handled by the URL encoder and decoder.

When a decode fails or looks wrong

What you seeLikely causeFix
Length or padding errorMissing or extra = at the end, or a cut-off stringCopy the whole string again; restore the padding
Unknown characterA space, quote or line break pasted in, or URL-safe text read as standardLeave the alphabet on Detect; remove stray quotes
Question marks or odd symbolsThe bytes are not UTF-8 textChange the text encoding of the result, or decode to a file
Result looks like random junkThe data is not text, it is an image, PDF or compressed fileSet the output to File and download it
Image will not display from a data URIMissing the data:image/...;base64, prefix, or a line break inside itTurn on the data URI option and leave wrapping off

Remember that decoding a Base64 string does not make an unreadable file readable. If the original was a ZIP or a photo, decoding gives you the ZIP or the photo, not text. The Base64 layer is only the wrapper.

Should you use Base64?

Use it when a channel only accepts text and you must send binary data through it: small inline icons, a field in a JSON API, an email body, a header. Avoid it when a normal file transfer is available, because the same data travels 33% heavier and loses the benefits of caching and streaming. For choosing between text formats more generally, see JSON vs CSV vs XML, which explains where each fits.

Frequently asked questions

What is Base64 encoding in simple terms?

It is a way of writing any data using only 64 plain characters (letters, digits, + and /) so it can pass through systems built for text. Every three bytes become four characters, and the receiver can reverse it exactly.

How do I decode a Base64 string?

Paste it into the Base64 decoder and choose whether the result should be text or a file. If it starts with data:image/png;base64, the prefix is recognised and removed for you, and the right file type is used for the download.

How do I turn an image into Base64?

Drop the image into the encoder and switch on the data URI option. You get a string starting with data:image/...;base64, that you can place in an HTML img tag or a CSS background. Keep the image small, since Base64 adds about 33% to its size.

Why is Base64 bigger than the original?

Because three bytes are written as four characters. Four divided by three is about 1.33, so the output is roughly a third larger, a little more once line breaks and padding are included.

Is Base64 secure or encrypted?

No. Base64 has no key and anyone can decode it instantly. It is a format change, not protection. Do not use it to hide passwords or private data.

What is the free limit for the Base64 tool?

Free encodes or decodes one file at a time, up to 25 MB. Pro queues up to 100 files and downloads them as a single ZIP. Typed text converts live as you type.

Keep reading

More in Documents →