Skip to content
TextBench Lab

Base64 Encode and Decode

Encode text or a file to Base64, or decode Base64 back to text or a file. Standard or URL-safe, padding, line wrapping and data URIs. It runs in your browser, so nothing is uploaded.

Mode
Up to 5 MB, read in your browser
Encode options
Input
0 bytes
Output
0 bytes
Change
-

Base64 is an encoding, not encryption. Do not use it to protect secrets.

How to encode and decode Base64

  1. Choose Encode or Decode

    Encode turns text or a file into Base64. Decode turns Base64 back into text or a file.

  2. Paste text or add a file

    Type or paste into the box, or choose a file or drop it on the box. Files up to 5 MB are read in your browser.

  3. Set the options

    For encoding, pick standard or URL-safe, padding, line wrapping, or a data URI. Decoding finds the format by itself.

  4. Copy or download the result

    Copy the result, download it as a file, or press Swap to send it back the other way.

Features

  • Text, files and images

    Encode any file up to 5 MB. Decoded images are previewed, and any decoded file can be downloaded.

  • Every common format

    Standard and URL-safe alphabets, padding on or off, 64 or 76 character lines, and data URIs.

  • Errors you can fix

    A bad character is shown with its position, and missing padding or line breaks never stop the decoder.

  • Private

    Everything happens in your browser. Your text and files are never uploaded or stored.

What Base64 is

Base64 is a way to write any data, including images, PDFs and other binary files, with only 64 safe characters: A to Z, a to z, 0 to 9, and two more symbols, normally + and /. It is defined in RFC 4648. It does not compress or hide anything. It only changes how the same bytes are written, so they can travel through places built for plain text.

A byte can have 256 values, and many of them are invisible control codes that older email systems and text formats could damage. Base64 takes the data 3 bytes at a time, splits those 24 bits into four groups of 6 bits, and writes each group as one of the 64 characters. The result survives copy and paste, email and JSON without a single bit changing.

Where you meet it

  • Data URIs. A small image or font can sit straight in HTML or CSS as text that starts with data:image/png;base64, followed by the Base64 of the file.
  • Email attachments. MIME (RFC 2045) sends attachments as Base64. The raw source of a message shows long blocks of it.
  • JSON and API payloads. JSON has no type for raw bytes, so APIs often send a file, a signature or a key as a Base64 string.
  • Tokens and headers. A JSON Web Token is usually three URL-safe Base64 parts joined with dots. HTTP Basic authentication sends the user name and password as Base64, which is one more reason to use it only over HTTPS.

Why the result is about 33% larger

Every 3 bytes become 4 characters, so the encoded text is four thirds of the original size: about 33% more. A 300 KB image becomes about 400 KB of Base64. Text is first turned into UTF-8 bytes. An English letter is one byte, but an accented letter or an Arabic or Urdu letter takes two, most Chinese characters take three, and an emoji takes four. So "😀" is 4 bytes and becomes 8 characters. The statistics under the result show the real numbers.

Standard and URL-safe Base64

Two characters cause trouble on the web. In a web address a + can be read as a space and a / separates the parts of the path, and / is not allowed in file names. RFC 4648 therefore also defines a URL and filename safe alphabet that uses - instead of + and _ instead of /. Choose it when the result goes into a link, a cookie or a file name. When you decode, you do not need to know which one you have: this decoder accepts both.

What the = padding means

Base64 works in groups of 4 characters. When the data does not split evenly into groups of 3 bytes, the last group is short, and one or two = signs fill it up. "f" becomes Zg== and "fo" becomes Zm8=, while "foo" fits exactly and becomes Zm9v. Some formats, such as JSON Web Tokens, leave it out, because the length already tells a decoder how many bytes are left. Switch off Add padding to match them. When decoding, missing padding is added for you.

Line wrapping: 76 and 64 characters

Some formats limit the line length. MIME email (RFC 2045) allows at most 76 characters per line, so mail programs break Base64 into lines of 76. PEM files, the text format used for certificates and keys, use lines of 64 characters between their BEGIN and END lines. For data URIs, JSON and most APIs, keep No line breaks. The decoder ignores line breaks and spaces.

Files and images

Choose a file, or drop it on the box, to encode it, and tick Output as data URI for HTML or CSS. The type comes from the first bytes of the file, so a PNG gets image/png. When you decode, common types such as PDF, ZIP, MP3 and the usual image formats are recognized and get a matching file name, and PNG, JPEG, GIF and WebP images are previewed. Other data is shown as a short hex dump. Decoded content is never run or inserted into the page, so an SVG or HTML file stays harmless text.

Base64 is not encryption

Base64 has no key and no secret. Anyone can decode it in a second, so data that only looks unreadable is not protected. Never use Base64 to hide passwords, tokens or personal data. For a password that is hard to guess, use the password generator and learn how to make a strong password you can remember.

Tips

  • An error message gives the position of the first bad character. Common causes are a missing piece at the end, a stray quote mark, or two strings pasted together.
  • Decoded API data is often JSON. Paste it into the JSON formatter to read it, and see the guide to fixing Unexpected token errors if it does not parse.
  • To see what changed between two versions of a text, use the text compare tool.

Privacy

Everything happens in your browser. Your text and files are not uploaded, saved or tracked, and there is no sign-up. Like every page on this site, this one may show ads from third-party vendors once ads are switched on, and those vendors can use cookies. Read the privacy policy for details.

Frequently asked questions

How do I decode a Base64 string?

Choose Decode and paste the string. Spaces, line breaks and a data URI prefix are ignored and missing padding is added. Text appears right away, other data can be downloaded as a file.

Is Base64 a kind of encryption?

No. Base64 only changes how data is written, and anyone can decode it without a key. Never use it to hide passwords or other secrets.

Why is the Base64 result bigger than my text?

Base64 writes every 3 bytes as 4 characters, so the result is about 33% larger. Accents, emoji and non-Latin letters also take more than one byte each before encoding.

What is the difference between standard and URL-safe Base64?

URL-safe Base64 uses - and _ instead of + and /, because those have a special meaning in web addresses and file names. The decoder accepts both.

Can I convert an image to Base64 or back?

Yes. Choose an image file and tick Output as data URI to use it in HTML or CSS. When decoding, PNG, JPEG, GIF and WebP images are previewed and any file can be downloaded.

Are my text and files uploaded?

No. Everything happens in your browser and nothing is sent or saved. Text is limited to 500,000 characters and files to 5 MB, so the page stays fast.

Topics