Base64 Encode and Decode

A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call

Free Base64 encoder and decoder. Encode text (UTF-8 safe) or files to Base64 and data URIs, or decode Base64 back to text, in your browser.

Input size
0
Output size
0
Output
Data URI

Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.

How to use the Base64 encoder and decoder

Choose what to do:

  • Text to Base64: type or paste text and get its Base64 encoding. Tick URL-safe to use - and _ instead of + and / and drop the = padding, for use in web addresses and tokens.
  • Base64 to text: paste Base64 and get the original text back. Spaces and line breaks are ignored, URL-safe Base64 is accepted, and a data:...;base64, prefix is removed automatically.

To turn a file into a data URI, such as an image to embed in HTML or CSS, choose it under "Or encode a file". Files up to 5 MB are accepted, and the result shows how much bigger the encoded version is.

Text is handled as UTF-8, so accented letters, other alphabets and emoji encode and decode correctly, which the browser's basic btoa() function gets wrong. If Base64 decodes to binary data rather than text (for example, an image), the tool tells you instead of showing garbled characters. Everything runs in your browser.

What Base64 is

Base64 is a way of writing any data, including text, images or files, using only 64 safe characters: A–Z, a–z, 0–9, + and /, with = for padding. It's defined in RFC 4648.

Many systems were built to handle text, not raw binary data. Email, URLs, JSON, HTML and many older protocols can mangle bytes that aren't ordinary characters. Base64 solves this by turning any data into plain text that survives being copied, pasted and transmitted.

How it works

Base64 takes the data three bytes (24 bits) at a time and splits them into four groups of 6 bits. Each 6-bit group, a number from 0 to 63, becomes one of the 64 characters. If the data doesn't divide evenly into threes, the output is padded with one or two = signs.

For example, the text Man (three bytes) becomes TWFu (four characters).

Because every 3 bytes become 4 characters, Base64 is about 33% larger than the original data.

Base64 is not encryption

This is the most common misunderstanding. Base64 hides nothing: anyone can decode it instantly, including with this tool. It's an encoding, like writing in a different alphabet, not a lock. Never use Base64 to "protect" passwords, API keys or private data. If you need secrecy, use real encryption, and keep secrets out of places where they could be seen.

Where you'll see Base64

  • Email attachments: MIME encodes attachments in Base64 so they travel safely as text.
  • Data URIs: small images and fonts embedded directly in HTML or CSS: data:image/png;base64,iVBORw0....
  • APIs and JSON: files and binary data sent inside JSON, which only allows text. The JSON formatter makes such responses readable.
  • HTTP Basic authentication: the Authorization: Basic header carries a username and password in Base64, which is why it must only be used over HTTPS.
  • Tokens: JSON Web Tokens (JWTs) are made of URL-safe Base64 parts.
  • Configuration files and certificates, such as PEM files.

URL-safe Base64

Standard Base64 uses + and /, which have special meanings in web addresses, and =, which is used in query strings. URL-safe Base64 (also called base64url) replaces + with - and / with _, and usually leaves out the padding. Use it for anything that goes in a URL, a filename or a token. For encoding ordinary text for URLs, the URL encoder and decoder is usually the right tool instead.

Data URIs: embedding files in a page

A data URI puts a file's contents directly into HTML or CSS:

<img src="data:image/png;base64,iVBORw0KGgo..." alt="Logo">

When it helps:

  • Tiny images and icons, to save a separate request.
  • Emails where linked images might be blocked (though many email apps don't display data URIs reliably).
  • Self-contained HTML files that must work offline.

When it doesn't:

  • Large images: Base64 makes them a third bigger, they can't be cached separately, and they slow down the page. Link to the file instead.
  • Images used on many pages, which browsers cache better as separate files.

As a rule of thumb, keep data URIs to small files of a few kilobytes. The tool warns you above 5 MB, and reports the size increase for every file. Before encoding an image, shrink it with the image resizer or image converter.

Why UTF-8 matters

The browser's built-in btoa() function only handles characters in the Latin-1 range. Give it "café ☕" and it throws an error or produces the wrong result. The Base64 encoder and decoder converts text to UTF-8 bytes first, then encodes those bytes, which is what every modern system expects. Decoding reverses it, and reports an error if the bytes aren't valid UTF-8 text.

Troubleshooting

  • "That isn't valid Base64": the text contains characters outside the Base64 alphabet, or has the wrong length. Check for missing characters at the start or end.
  • Decodes to binary data: the Base64 is probably an image or file, not text. If it's an image, put data:image/png;base64, in front of it and open it in a browser address bar to see it.
  • Strange characters after decoding: the original text may have been in a different character encoding before it was Base64-encoded.
  • Line breaks in the Base64: some systems wrap Base64 at 76 characters. The decoder ignores line breaks and spaces.

Base64 in code

Most programming languages include Base64 functions:

  • JavaScript (browser): btoa() and atob() handle Latin-1 text only. For any other text, convert to UTF-8 bytes first with TextEncoder, as this tool does.
  • Node.js: Buffer.from(text, "utf8").toString("base64") encodes, and Buffer.from(b64, "base64").toString("utf8") decodes. Use "base64url" for the URL-safe variant.
  • Python: the base64 module, with b64encode, b64decode and urlsafe_b64encode.
  • Command line: base64 on macOS and Linux, and certutil -encode on Windows.

Results from any of these should match this encoder exactly for the same input bytes. If they don't, the usual cause is a different text encoding, or a line break added at the end of the input.

Padding explained

The = signs at the end of standard output show how many bytes were missing from the final group of three:

  • No =: the data length was a multiple of 3.
  • One =: the last group had 2 bytes.
  • Two ==: the last group had 1 byte.

Some systems leave padding out, especially for URL-safe output. The decoder here accepts input with or without padding.

Other encodings you might mean

  • URL encoding (percent-encoding) turns spaces into %20 and other special characters into % codes. It's for text in web addresses, not for binary data.
  • HTML entities turn characters like < into &lt; so they display in a page instead of being read as code.
  • Hex encoding writes each byte as two hexadecimal digits, so it's twice the size of the original data, compared with a third larger for this encoding.

Checking your result

A quick way to check an encoding is to decode it again and compare it with the original. With this tool, copy the output, switch to "Base64 to text", paste it, and you should see your original text exactly.

A worked example

A bakery's developer wants the shop's small logo icon embedded in an HTML email template, so it shows even before images load from the server. The icon is a 1.8 KB PNG. Choosing it under "Or encode a file" gives a data URI of about 2.4 KB, about a third larger, as expected. The developer pastes it into the template's <img> tag. For the larger product photos, they keep normal links, because encoding them would make the email much heavier.

Need more customers from Google?

This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. That is the whole job of DeepRit: a PPC-only agency that sets up and runs Google Ads accounts so every click is accounted for. You keep full ownership of your account, get a written report every week, and can stop at any time. See our pricing or ask for a free audit.

Frequently asked questions

What is Base64 encoding?

A way of writing any data using 64 plain-text characters, so it can travel safely through systems that only handle text, such as email and JSON.

Is Base64 encryption?

No. Anyone can decode Base64 instantly. Never use it to protect passwords or private data.

Why is Base64 bigger than the original?

Every 3 bytes of data become 4 characters, so encoded data is about 33% larger.

What is URL-safe Base64?

A variant that uses - and _ instead of + and /, and usually drops = padding, so it can go in web addresses and tokens.

How do I convert an image to Base64?

Choose the image under "Or encode a file" and copy the data URI, which you can use in HTML or CSS.

Is the Base64 encoder and decoder free?

Yes. It's free with no sign-up, and it runs entirely in your browser.

Free PPC audit

See where your ad budget leaks.

We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.

Book a free audit call 30-minute call · Free · The audit is yours to keep