Travel the world

Climb the mountains

Post Page Advertisement [Top]

GuidesText Tools

Base64 Encoder and Decoder: How to Encode Text and Images Online

Copy a block of text into an online tool, click one button, and out comes a string of letters, numbers, plus signs and equal signs that looks like gibberish. That is Base64 — and if you work with websites, APIs, email or code, you will run into it sooner or later. The good news is that it is far simpler than it looks: Base64 is just a way of rewriting any data — text, an image, a file — using only 64 safe, plain-text characters, so it can travel through systems that only handle plain text.

In this guide you will learn exactly what Base64 is, how encoding and decoding work step by step, when developers actually use it, and how to encode text and images online in seconds. Every example below has been encoded and decoded to check it is correct, so you can copy any of them with confidence.

What Is Base64?

Base64 is a binary-to-text encoding scheme. That sounds technical, but the idea is simple: computers store everything as bytes, and bytes can hold any value from 0 to 255. Some of those values are control characters, line breaks or symbols that break things when they pass through email servers, web addresses, JSON files or old text-only systems. Base64 solves the problem by converting any bytes into a string made only of safe characters.

The "64" in the name comes from the alphabet it uses: the uppercase letters A–Z (26), the lowercase letters a–z (26), the digits 0–9 (10), and two extra symbols, + and /. That is 26 + 26 + 10 + 2 = 64 characters. A final character, the equals sign =, is used as padding at the end when the input does not divide evenly. Because the output contains only letters, digits, + , / and =, it can be pasted into an email, a JSON file, a URL parameter or a line of code without anything getting mangled along the way.

One thing to get straight right away: Base64 is not encryption. Anyone who sees a Base64 string can decode it in one click. It hides nothing and protects nothing. Its job is transport, not secrecy — it makes data safe to carry, not safe from prying eyes. Never encode a password or a secret with Base64 and assume it is protected.

How Does Base64 Encoding Work?

Here is the process in plain English. Your input is a stream of bytes, and each byte is 8 bits. Base64 groups those bits into chunks of 6 bits instead of 8. Each 6-bit chunk can hold a value from 0 to 63, and each value maps to one character in the 64-character alphabet. A is 0, B is 1, C is 2, and so on through Z (25), then a is 26 through z (51), then 0 is 52 through 9 (61), then + is 62 and / is 63.

Because 3 bytes (24 bits) divide neatly into 4 chunks of 6 bits, every 3 bytes of input become exactly 4 characters of output. That is where the famous size overhead comes from: 4 characters out for every 3 bytes in, which means the encoded text is about one-third larger than the original. We will do the exact math below.

When the input length is not a multiple of 3, padding steps in. One leftover byte produces two Base64 characters followed by ==, and two leftover bytes produce three characters followed by a single =. That is why so many Base64 strings end in one or two equals signs. The padding is not decoration — it tells the decoder exactly how many bytes to reconstruct, so the output is always a multiple of 4 characters long.

How to Encode Text Online

Encoding text with a free online Base64 encoder takes less than a minute, and the steps are the same on almost every tool:

1. Open a Base64 encoder. Search for a free Base64 encoder and decoder, or use the text tools on this site. You do not need to install anything, and you do not need an account.

2. Paste or type your text into the input box. It can be a single word, a sentence, a paragraph, a block of code or a JSON snippet.

3. Click Encode. The tool converts your text to Base64 instantly. Copy the result from the output box.

4. Decode to check your work. Paste the encoded string into the decoder side of the same tool and confirm you get your original text back. If you are sending the string to someone else, this quick check catches typos before they cause trouble.

If you would rather do it in code, most languages have it built in. In JavaScript, btoa("Hello") returns "SGVsbG8=", and atob("SGVsbG8=") turns it back into "Hello". In Python, base64.b64encode(b"Hello") gives the same result. One warning for JavaScript users: btoa only handles Latin-1 characters, so text with emoji or accented characters needs to be converted to UTF-8 bytes first, or the function throws an error.

Base64 Encode Examples (Verified)

The fastest way to understand Base64 is to see real examples. Each row below was produced by actually encoding the text, then decoding the result to confirm it matches. Try decoding any of them yourself in an online decoder.

Original textBase64 encoded
HelloSGVsbG8=
Hello WorldSGVsbG8gV29ybGQ=
Base64QmFzZTY0
I love coding!SSBsb3ZlIGNvZGluZyE=
user@example.comdXNlckBleGFtcGxlLmNvbQ==
Base64 is not encryptionQmFzZTY0IGlzIG5vdCBlbmNyeXB0aW9u
The quick brown fox jumps over the lazy dogVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==

Look closely at the patterns. "Hello" is 5 bytes, which is not a multiple of 3, so its encoding ends in a single =. "user@example.com" is 16 bytes, leaving one byte over, so it ends in ==. "Base64" is exactly 6 bytes — two clean groups of 3 — so it needs no padding at all. And "Hello World" shows how spaces are handled: the space becomes part of the bytes, so it is encoded just like any other character, with nothing special to remember.

Now decode one in reverse. Take SGVsbG8gV29ybGQ= and run it through any Base64 decoder. You will get back Hello World — the space included, exactly as it went in. That round trip is the whole point: encode, transport, decode, and nothing is lost.

How Much Bigger Does Base64 Make Data?

Base64 output is always about 33% larger than the input, because every 3 bytes become 4 characters. The exact overhead is one-third: (4 ÷ 3) − 1 = 33.33%. Here is what that means for real sizes:

Original sizeBase64 sizeExtra
3 bytes4 characters+1 (33%)
6 bytes8 characters+2 (33%)
100 bytes136 characters+36 (36%)
1,000 bytes1,336 characters+336 (33.6%)
1 KB (1,024 bytes)1,368 characters+344 (33.6%)

The small sizes look slightly worse than 33% because of padding — a 100-byte input needs padding to round up to a multiple of 4 characters. As files get bigger, the overhead settles at almost exactly one-third. That matters when you embed images in a web page: a 30 KB logo becomes roughly 40 KB of Base64 text. For a small icon, that trade-off is usually worth it because it saves a separate file request. For a large photograph, it is not — the image should stay a separate file.

How to Encode an Image to Base64

Encoding an image works the same way as encoding text, except the input is the image file itself rather than words you type. Most online tools let you upload a JPG, PNG, GIF or SVG and give you back a long Base64 string, usually wrapped in a data URI that a browser can display directly.

A data URI looks like this: data:image/png;base64, followed by the encoded image data. Put that whole string as the src of an <img> tag, and the browser renders the image without downloading any file. Here is a real, complete example — a tiny 1 × 1 pixel transparent PNG, which is 66 bytes as a file and 88 characters once encoded:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAAACAAEA6QqbAAAAAElFTkSuQmCC

That string really is a valid image: decode the part after the comma and you get back the exact 66-byte PNG file. Real images produce much longer strings — a small 10 KB icon becomes roughly 13,700 characters — so you would never type one by hand. The practical workflow is: upload the image to an encoder, copy the data URI, and paste it into your HTML or CSS.

Developers use this trick most often for small icons, logos and background patterns in CSS, where embedding the image directly means the browser makes one fewer request. It also shows up in single-file HTML email templates, where attached images may be blocked but an embedded data URI still displays. Keep it to small images, though: anything over a few tens of kilobytes is better left as a normal image file, both for page size and because Base64 text cannot be cached separately by the browser.

When Do Developers Use Base64?

Base64 shows up in more places than most people realise. Here are the everyday uses, with a concrete example for each.

Embedding images and fonts in web pages. A small logo or an icon font can be embedded directly in HTML or CSS as a data URI, so the page needs no extra download. This is the single most common use front-end developers meet.

Sending attachments in email. Email was designed for plain text, so attachments are Base64-encoded inside the message body using the MIME standard. When you attach a photo to an email, your mail app quietly encodes it, and the recipient's app decodes it back into a file.

Carrying binary data in JSON and APIs. JSON can only hold text, numbers and a few other types — not raw bytes. When an API needs to send a small file, a thumbnail or a signature inside a JSON response, it Base64-encodes the bytes first. The receiver decodes them on arrival.

Basic authentication headers. HTTP Basic Auth sends a username and password as username:password, Base64-encoded, in the Authorization header. For example, dXNlcjpwYXNzd29yZA== decodes to user:password. Again, this is encoding, not encryption — anyone who intercepts the header can decode it, which is why Basic Auth is only ever used over HTTPS.

Storing small binary values in text files and databases. Configuration files, data URIs in SVG graphics, and some database fields store images, keys or hashes as Base64 strings simply because text is easier to copy, paste and version-control than raw binary.

Base64 vs. Encryption, Hex and URL-Safe Base64

People often confuse Base64 with three neighbouring ideas, so here is the quick separation.

Base64 is not encryption. Encryption needs a key, and without the key the data stays unreadable. Base64 needs no key at all — the alphabet is public, and every decoder in the world reverses it the same way. If you need secrecy, encrypt first, then Base64-encode the encrypted bytes if they have to travel as text. Encoding alone is like writing a private letter in a different alphabet that everyone knows how to read.

Base64 is not the same as hexadecimal. Hex encoding turns each byte into two characters (0–9 and a–f), so it doubles the size — a 100% overhead, against Base64's 33%. Hex is more readable for humans debugging bytes, but Base64 is more compact, which is why APIs and email prefer it.

Standard Base64 vs. URL-safe Base64. The standard alphabet contains + and /, which have special meanings inside URLs, and padding = signs, which can confuse some servers. URL-safe Base64 swaps + for - and / for _, and usually drops the padding entirely. If you have ever seen a long token in a web address or a JWT (JSON Web Token), you have seen URL-safe Base64. Use the standard version for email and data URIs, and the URL-safe version for anything that lives inside a link.

Common Base64 Mistakes (and How to Avoid Them)

Forgetting the padding. A Base64 string must be a multiple of 4 characters long. If you copy a string and accidentally drop the trailing = signs, most decoders will refuse it or produce the wrong bytes. Always copy the full string, equals signs included.

Breaking the string across lines. Older email systems wrapped Base64 at 76 characters per line. If you paste a wrapped string into a decoder without removing the line breaks, some tools fail. Modern decoders usually ignore whitespace, but when in doubt, remove line breaks first.

Encoding the wrong character set. Base64 encodes bytes, not characters, so the same text can produce different Base64 in different encodings. Always encode as UTF-8, the web standard. This is also why JavaScript's btoa chokes on emoji: it expects Latin-1, not UTF-8. Convert first, then encode.

Using standard Base64 in a URL. A + in a URL can be read as a space, and a / can be read as a path separator. If your encoded string goes into a web address, use the URL-safe variant or URL-encode the string. Getting this wrong is one of the most common causes of "invalid token" errors.

Treating it as security. This one is worth repeating, because it causes real breaches: Base64 hides nothing. API keys, passwords and personal data must never be "protected" by encoding alone.

Frequently Asked Questions

What is Base64 encoding used for?

Base64 is used to send binary data — images, files, attachments — through systems that only handle plain text, such as email, JSON APIs and URLs. It converts any bytes into a string of 64 safe characters so nothing gets corrupted in transit.

How do I decode Base64 online?

Paste the Base64 string into the decode box of any free online Base64 decoder and click Decode. The original text appears instantly. If the string ends in = padding, include it — dropping it is the most common reason a decode fails.

Is Base64 encryption?

No. Base64 is an encoding, not encryption. There is no key, and anyone can reverse it in one click. It makes data safe to transport, not safe from readers. Use real encryption, such as AES, when data must stay secret.

Why is Base64 output about 33% larger?

Base64 repacks 3 bytes (24 bits) into 4 characters of 6 bits each, so the output is always 4/3 the size of the input — a 33.33% increase. A 1 KB file becomes about 1,368 characters, and a 100-byte message becomes 136 characters.

Can I encode an image to Base64 for free?

Yes. Free online Base64 image encoders accept JPG, PNG, GIF and SVG files and return a data URI you can paste straight into HTML or CSS. It works best for small images; large photos are better kept as separate files because of the 33% size overhead.

The Bottom Line

Base64 is one of those quiet tools that holds a surprising amount of the web together. It is not glamorous, it is not secure, and you will probably never need to encode anything by hand — but the moment you embed an icon in a page, attach a file to an email or pass binary data through an API, it is doing the work in the background. Remember the three essentials: it turns any bytes into 64 safe characters, it grows data by about a third, and it is encoding, never encryption.

Try it yourself right now: take the sentence "The quick brown fox jumps over the lazy dog", encode it, and check that you get VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==. Then decode it back. Once you have done that round trip once, Base64 stops looking like gibberish and starts looking like what it is — a simple, reliable way to move data around the internet.

Working with text for the web? Our Character Counter guide shows how to count characters for Instagram captions and meta descriptions, and our Word Counter guide explains how to count words and characters for essays and SEO articles — both useful companions when you are preparing text to encode or publish.

No comments:

Post a Comment

Bottom Ad [Post Page]