Cookies This site keeps only what it needs to work. There is no analytics and no advertising on it today, and nothing here follows you to other sites. Read the privacy policy

Choose what to allow
+92 312 8299940Free Quote
EN – Language: English
Blog

What Is Base64? A Plain-English Guide

What is Base64? A plain-English explanation of how it works, where it's used in images, email and APIs, and the 33% size cost.

By Daniyal Subhani 10 min read

The Problem Base64 Solves

Computers store everything as bytes. Some systems were built to handle only plain text, not arbitrary binary data. Email is the classic instance. The old email system was designed for text. It could choke on the raw bytes of an image or a program.

What Is Base64? A Plain-English Explanation
What Is Base64? A Plain-English Explanation

To solve this problem, the binary data of the image or program has to be translated into plain text. This plain text representation is Base64. Base64 is a translation mechanism to show raw bytes using 64 printable characters. Unlike binary data which may contain many different characters, Base64 representation only contains printable characters. This allows text systems to carry the data without corruption.

Its like spelling a word using “A as in Apple, B as in Boy.” With words, you’re just rephrasing them in a way people can grasp over a bad phone line. Base 64 is similar in the sense that it shows the data in a different way to survive the channel.

How Base64 Works, Simply: What is base64

The deep math isn't necessary. It's an useful concept. Base 64 takes groups of 3 bytes of data and divides them into groups of 4. Each group shows one of 64 characters.

Those 64 characters are the uppercase letters A to Z, the lowercase a to z, the digits 0 to 9. Two symbols, usually plus and slash. That's 26 plus 26 plus 10 plus 2, which equals 64, hence the name.

With three bytes making four characters, the length of the data showed in Base 64 is always longer than the original data. If the original data doesn't evenly divide by three, Base 64 will pad the end of the representation with ‘=’ (one or two of them). Because of this, most Base 64 representation end with ‘=’ or ‘==’.

A Quick Example

Seeing it helps. Take the simple word "Hi". In Base64, it becomes:

Hi  ->  SGk=

Base 64 gives no security or encryption of any kind. It just ‘shows’ the data in a different way, like spelling a word. To decode SGk= for instance, you would get the letter ‘Hi’. Since Base 64 always results in a representation about 33% longer than the original data, if you were to input a longer phrase you would get a longer string of data. Reversibility is key here.

This reversibility is the whole point. Encode to travel safely, decode on the other side. You have your original data back, byte for byte.

Where You'll Run Into Base64

Base64 has many uses. Here are a few instances.

WhereWhy Base64 is used
Email attachmentsSends binary files through text-based email
Data URLs in HTML/CSSEmbeds a small image directly in the code
API tokens and authEncodes credentials for transport (not security)
JSON web tokens (JWT)Encodes the token's parts into text
Storing binary in text fieldsFits image data into a text-only database column

Data URLs are used quite commonly. Using this method, you can embed an image in either your HTML or CSS using Base64 encoding like this: data:image/png;base64,iVBORw0... To embed an image in your HTML or CSS using Base64 encoding, you have to use a data URL. This is most useful when embedding small images to avoid making an extra network request.

The Size Cost

But using Base64 encoding comes at a cost. Every three bytes of data is extended to four characters of Base64 encoding. So the size of the data is increased by about 33%.

That matters in practice. A 90 KB image becomes about 120 KB as Base64. For a tiny icon embedded in CSS, that overhead is negligible and the saved network request is worth it. For a large image, the 33 percent bloat outweighs any benefit. You'd link to the file normally instead.

Using Base64 should be avoided unless it is really needed. Base64 should always be avoided if there is no need to transmit binary data using text.

Base64 Is Not Encryption

Misconceptions about Base64 encoding causes many security issues. Base64 encoding is not a means of securing data. It should never be used to encrypt or hash data.

Decoding Base64 is extremely simple and takes no time at all. Decoding a Base64 string takes less than a second with an online tool or with a single line of code. If you Base64 encode a password and send it or store it that way you've in short secured nothing and the attacker wouldn't have to decode it. It offers absolutely no security.

Base64, in conjunction with other security mechanisms, increases confusion. JWTs or auth headers may be Base64 encoded. That does not increase the security of the mechanism. The security comes from signing or encryption that is done separately. The Base64 encoding is simply packaging and should not be used to conceal or obfuscate data.

A Real-World Example

Let’s say you’re creating a small website and you have a 2 KB logo that you use many times. Whenever that logo is loaded, the browser also has to make a separate request for the logo file, increasing page load time.

You Base64-encode the logo and paste it directly into your CSS as a data URL. Now the image travels inside the stylesheet itself. The browser doesn't make a separate request for it. The page feels a touch snappier. The cost is that the encoded logo is about 33 percent larger than the file. For 2 KB that's trivial, well worth saving a round trip. Try the same with a 500 KB hero image, though. The bloat and the giant inline blob aren't worth it. You'd link to that one normally.

Using the right tool for the right job is the skill here.

How to Encode and Decode Base64

Encoding and decoding is instant and free. A browser tool lets you paste text or upload a file and get the Base64 version. Paste Base64 and get the original back. The free [Denwix tools](here can handle Base64 along with other text utilities.

For the technical definition, [MDN's Base64 guide](here explains how it works in web development. @CAP@[the RFC that defines it](here is the formal spec. Both confirm the key point: it's encoding, not security.

The Bottom Line

Base64 is a way to encode binary data, to show it in text form, to allow that data to be transmitted in an email or HTML for instance. The encoding increases the size of the data by about 33%. Any extra binary data is showed by equals signs. Using Base64 to transmit sensitive details should never be done. The purpose of Base64 is to allow binary data to be transmitted in a text form. Should never be used for security of any kind.

Questions and Answers

What is Base64?

As mentioned, Base64 is a way to show binary data using 64 safe characters. It is often used to show images or files in text form to allow transmission through email or HTML for instance.

Is Base64 encryption?

Base64 is an encoding method and should not be mistaken for an encryption method. Something encoded using Base64 can be decoded by anyone at any time so it should not be used to protect or encode sensitive details.

How does Base64 work?

It takes data three bytes at a time and re-splits the bits into four groups, each mapped to one of 64 characters: A to Z, a to z, 0 to 9, plus. Slash. Three bytes become four characters.

Why does Base64 end in equals signs?

The equals signs are padding. When the input doesn't divide evenly into groups of three bytes, Base64 adds one or two equals signs at the end to complete the final group.

What are the 64 characters in Base64?

The uppercase letters A to Z, the lowercase a to z, the digits 0 to 9. Two symbols, usually plus and slash. That's 26 plus 26 plus 10 plus 2, which equals 64.

Why is Base64 used in email?

Email was created to transport text. As a result, attachments have to be converted to text using a mechanism known as Base64 encoding before being sent. Raw binary data can be corrupted when sent via email. At the receiving end this data is decoded back to its binary form.

How much bigger does Base64 make data?

About 33% larger. Because 3 bytes are showed by 4 characters, the output is about 33% larger than the input. So, a 90 KB file would increase in size to about 120 KB when encoded using Base64.

Can Base64 be decoded?

Surely. Base64 is exactly reversible. This means that Base64 decoding will return the original data in exactly the same form as before the encoding.

Is Base64 safe for passwords?

Not at all. Base64 has no encryption capabilities. Anyone can decipher Base64 encoded passwords.

What is a data URL?

Using a data URL allows you to include a small file, often an image, directly in HTML or CSS using Base64 encoding like “data:image/png;base64,…”. This eliminates the need for a separate network request to retrieve that file.

When should I use Base64 for images?

Data URLs should be used to embed small images in CSS to save a network request. Use of data URLs to embed larger images would be detrimental as the 33% increase in size would outweigh any benefits.

What is the difference between Base64 and encryption?

Textual representation of data using Base64 is easily reversible and gives no security. Encryption is used to scramble data. They are fundamentally different and serve different purposes.

Why do API tokens use Base64?

To transport credentials or token parts in an easily readable format. Base64 encoding is not protection of data. Real protection is gave by other means such as encryption or signing.

What is Base64 in a JWT?

Security in a JSON Web Token is gave by the cryptographic signature and not Base64 encoding which just reformats the data for transport.

Can I Base64 encode any file?

Yes. Any kind of binary data can be encoded using Base64 and vice versa. Base64 encoded data is always larger than the original by about a third.

How do I decode a Base64 string?

Copy it into an online Base64 decoder or use a one line function in your programming language of choice. The data is decoded and returned to its original state.

Is Base64 the same as hexadecimal?

No, they both show binary data using text. Hexadecimal uses 16 characters to show data, while Base64 uses 64 characters.

Does Base64 slow down my website?

Because of the base 64 encoding’s size increase it can be inconvenient to embed large images. For smaller images it can reduce the number of server requests.

What does the plus and slash mean in Base64?

They are two of the 64 characters used to show 8 bit patterns in binary. The URL safe variant uses dash and underscore to show the characters so that the string can be safely embedded in a URL.

Why do I see Base64 strings in HTML?

They are mostly data URLs that embed a small image in the page. The string of characters is actually the binary data that shows the image.

Is Base64 the same as encryption?

No. Base 64 encoding is reversible and so does not give security. Encryption is scrambling data in such a way that only the holder of the key can read the data.

Why is Base64 used in data URLs?

This is embedding a small file, usually an image, directly in an HTML or CSS file as text. This can speed up the loading time by eliminating the need for a separate data request.

How do I decode Base64 in a browser?

The string of characters can be decoded using many online resources or the javascript function atob().

Does Base64 work for any file type?

Yes. Any kind of binary file can be Base64 encoded and decoded. The output is usually about 33% bigger than the input.

What is URL-safe Base64?

A base64 encoded string should be URL safe, meaning it should not contain characters which need special escaping in a URL. Variations of base64 can be used for this purpose.

Why does Base64 add about a third to the size?

It's basically a encoding where 3 bytes are showed using 4 characters. So, the output is always 33% larger than the input.

Can I store Base64 in a database?

Yes. Using base64 encoding, binary data can be showed using text. Though, it takes up more space so it is not efficient to base64 encode large files.

Is it safe to put a password in Base64?

No. Base64 hides nothing and is decoded in seconds. Never use it to protect a password. Use proper hashing and encryption for any sensitive value.

Video guide

What Is Base64? A Plain-English Explanation

This brief video shows each step from start to finish. Choose your language below, and switch on captions if they help.

Try It in Your Browser

Open the free Base64 Encode Decode and do it now, right in your browser.

Prefer Denwix on GoogleReview Denwix on Google