Base64 Encode & Decode

Convert text to and from Base64 with emoji and accents intact, turn files into data URIs, and decode Base64 back into a file you can save.

Runs entirely in your browser. Nothing you add is sent to us.

Create a free account to use the Base64 Encode & Decode

Free forever for this tool. Takes a few seconds — then you come straight back here.

  • All 150 free tools, one login
  • Free website audit with fixes
  • Search Console dashboard
  • Free keyword rank tracker

Already have an account? Sign in

How to use the Base64 Encode & Decode · 45 sec

Base64 Encode & Decode — base64 encode decode

Base64 is a way of writing any data, from a sentence to a photo, using only 64 safe text characters, so it can travel through systems that were built for plain text. Our free tool lets you encode and decode Base64 in both directions. Text is converted as UTF-8, so accents, non-Latin scripts and emoji survive the round trip. You can switch to the URL-safe variant used in web tokens and links, turn any file into Base64 or a ready-made data URI with its size shown, and decode Base64 back into a file you can download. Nothing is uploaded: every conversion happens in your browser.

How to use the Base64 encoder

  1. 1 Choose a modeUse the Text tab for words and short strings, File → Base64 to encode a file, or Base64 → file to turn encoded data back into a file.
  2. 2 Encode or decode textPick Encode or Decode and paste your input. The result updates as you type, and the Swap button sends the output back as new input to check a round trip.
  3. 3 Set the optionsTick URL-safe to use - and _ instead of + and / with no padding, or wrap lines at 76 characters for email (MIME) content.
  4. 4 Encode a fileChoose or drop a file to get its Base64, a full data URI, or ready-to-paste HTML and CSS snippets, with the original and encoded sizes shown.
  5. 5 Decode to a filePaste Base64 or a data URI. The tool detects the file type, previews images, and lets you download the file with the right extension.

What Base64 is and how it works

Computers store everything as bytes, and a byte can hold any of 256 values. Many older protocols and formats, such as email, URLs, XML and JSON, were designed for text and can mangle or reject bytes that are not ordinary printable characters. Base64 solves this by rewriting data using just 64 characters that are safe almost everywhere: the capital letters A to Z, the small letters a to z, the digits 0 to 9, and the plus and slash signs.

It works by taking the input three bytes at a time. Those 24 bits are split into four groups of six bits, and each group, a number from 0 to 63, is replaced by one character from the alphabet. When the input does not divide evenly into threes, one or two equals signs are added at the end as padding. Decoding simply reverses the process. Because four characters represent three bytes, Base64 output is always about a third larger than the original data.

Base64 and UTF-8 text

Base64 encodes bytes, not letters, so text first has to be turned into bytes using a character encoding. This tool always uses UTF-8, the standard encoding for the web. That means "Café ☕" becomes the bytes for each character, including the two bytes for é and three for the coffee cup, and then those bytes are encoded.

This matters because the browser's own btoa function only accepts characters in the Latin-1 range and throws an error for anything else, such as emoji or Polish, Greek and Arabic letters. Many quick online encoders use it directly and either fail or produce the wrong result. When decoding, the tool checks that the bytes form valid UTF-8 text. If they do not, the data is almost certainly binary, such as an image or a PDF, and you are offered a hex preview and the option to save it as a file instead.

Standard and URL-safe Base64

The plus and slash characters in standard Base64 have special meanings in URLs and file names. A plus can be read as a space in a query string, and a slash looks like a folder separator. The URL-safe variant, defined in RFC 4648, swaps them for a minus sign and an underscore. The padding equals signs are usually dropped as well, because = also has a meaning in query strings.

You will meet URL-safe Base64 in JSON Web Tokens, signed links, some API keys and cloud storage identifiers. Tick URL-safe when you are producing a value for one of these. When decoding, you do not need to choose: the tool accepts both alphabets, with or without padding, and ignores spaces and line breaks.

Data URIs: embedding files in HTML and CSS

A data URI packs a whole file into a single string that starts with data:, followed by the file type, the word base64 and the encoded content. Browsers treat it just like a link to a file, so you can use it in an image tag, a CSS background or a font declaration without a separate download.

Inlining is handy for tiny assets such as a small icon, a loading spinner or an email signature logo, and for self-contained HTML files that must work offline. It is a poor choice for larger images. The encoded file is a third bigger, it cannot be cached separately from the page or stylesheet, and it delays the rest of the HTML from loading. As a rule of thumb, link to anything bigger than a few kilobytes as a normal file. If your site uses a Content Security Policy, data: must also be allowed in the relevant directive, such as img-src, for inlined images to display.

  • Data URI: data:image/png;base64,iVBORw0KGgo… for use anywhere a URL is accepted.
  • HTML: an img tag with the data URI as its src attribute.
  • CSS: a background-image declaration using url() with the data URI.
  • Base64 only: just the encoded characters, for APIs and JSON fields that expect raw Base64.

Decoding Base64 back into a file

APIs often return files such as PDFs, invoices, signatures or images as Base64 strings inside JSON, and email attachments are stored as Base64 inside the raw message. To turn one back into a usable file, paste it into the Base64 → file tab. If it begins with a data: prefix, the file type is read from that. Otherwise the tool looks at the first few bytes, which act as a signature for common formats such as PNG, JPEG, GIF, WebP, PDF, ZIP and MP3, and suggests the right extension.

Images are previewed so you can confirm you have the right data before downloading. If the decoded data is plain text, such as JSON or XML, the tool says so, and it falls back to a generic binary file when the format is not recognised. Name the file however you like; the detected extension is added if you leave it off.

If decoding fails, the error message explains why. The most common causes are a character that is not part of the Base64 alphabet, such as a stray quote mark copied from a JSON file, padding in the wrong place, or a string that has been cut short. Check that you have copied the whole value from the very first character to the last, including any equals signs, and that you have not included surrounding text such as a field name or a closing bracket.

Base64 is not encryption

Base64 is often mistaken for a way of hiding information because the output looks like gibberish. It offers no protection at all. There is no key, the method is public, and anyone can decode a Base64 string in seconds with a tool like this one. Basic authentication headers, many configuration files and the payload of every JSON Web Token are only Base64-encoded, so their contents are readable by anyone who can see them.

If you need to keep data private, use proper encryption, and protect it in transit with HTTPS. Treat any Base64 that contains passwords, API keys or personal data with the same care as the plain text. Because this tool runs entirely in your browser, nothing you paste or select is uploaded, which makes it safe to inspect sensitive values without sending them to a third party.

Examples you can copy

Text encoded as UTF-8 Base64

Text:           Café ☕
Base64:         Q2Fmw6kg4piV

Text:           hello?
Standard:       aGVsbG8/
URL-safe:       aGVsbG8_

A tiny image as a data URI

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" alt="">

.icon { background-image: url("data:image/svg+xml;base64,PHN2Zy…"); }

Common mistakes to avoid

Using Base64 to hide secrets

Base64 is an encoding, not encryption. Anyone can reverse it, so never rely on it to protect passwords or personal data.

Inlining large images

Data URIs add about a third to file size and cannot be cached separately. Keep them for tiny icons and link to larger files normally.

Mixing standard and URL-safe alphabets

A system that expects standard Base64 may reject - and _, and one that expects URL-safe may break on + and /. Check what the receiving system needs.

Decoding binary data as text

Images, PDFs and compressed files turn into garbled characters if shown as text. Decode them to a file instead.

Losing padding or characters when copying

A Base64 string cut short by an email client, terminal or chat app will not decode correctly. Copy the whole value, including any trailing = signs.

Frequently asked questions

No. Base64 only changes how data is written so it can travel through systems built for text. Anyone can decode it instantly, so never use it to hide passwords or personal data.

Base64 uses four characters for every three bytes, so encoded data is about a third larger than the original, plus a little padding.

Standard Base64 uses A–Z, a–z, 0–9, + and /, with = for padding at the end. The URL-safe variant replaces + with - and / with _ and usually leaves out the padding.

Either the original text was encoded with a different character set than UTF-8, or the data is binary, such as an image. Try the Base64 → file tab to see what type of file it is.

Files up to 25 MB can be encoded. Larger files make very long strings that are slow to display and rarely useful as Base64.

They are padding, added when the input length is not a multiple of three bytes. One = means one byte of padding, two means two. Some systems leave them out, and this tool decodes either way.

Yes. Copy the Base64 block of the attachment from the raw message source, without the MIME headers, and paste it into the Base64 → file tab.

Yes. Spaces and line breaks are ignored when decoding, so wrapped Base64 from emails, PEM files and logs decodes correctly.

Free website audit

See how your site scores, free

Speed, SEO, DNS, email (SPF/DKIM/DMARC) and security in one scan, with a prioritised fix list.