What is Base64 encoding?

Base64 turns binary data into plain text using 64 safe characters. Learn how it works, why it adds about 33% to size, Base64url, and why it is not encryption.

Base64 in one paragraph

Base64 is a way to represent any binary data, such as an image, a file or text in any language, using only 64 printable characters. It exists because many systems were designed to carry text, not raw bytes. Email, JSON, XML, URLs and HTML attributes can mangle or reject arbitrary bytes, but they pass letters and digits through safely. Base64 converts bytes into text for the trip, and the receiver converts them back exactly.

The Base64 alphabet

The standard alphabet, defined in RFC 4648, uses these 64 characters, each representing a 6-bit value from 0 to 63:

  • A to Z for values 0 to 25.
  • a to z for values 26 to 51.
  • 0 to 9 for values 52 to 61.
  • + for 62 and / for 63.
  • = is not part of the 64. It is padding added at the end when needed.

How encoding works

Base64 works on groups of three bytes, which is 24 bits. Those 24 bits are split into four 6-bit chunks, and each chunk becomes one character from the alphabet. Three bytes in, four characters out.

Take the word Man. Its three bytes are 77, 97 and 110. In binary they are 01001101 01100001 01101110. Regrouped into 6-bit chunks this gives 010011 010110 000101 101110, which are 19, 22, 5 and 46, or T, W, F and u. So Man encodes to TWFu.

When the input is not a multiple of three bytes, the last group is padded. One leftover byte produces two characters plus ==, and two leftover bytes produce three characters plus =. For example, Hi encodes to SGk=.

Why Base64 makes data about 33% larger

Every 3 bytes become 4 characters, so encoded data is 4/3 the size of the original, an increase of about 33%, plus up to two padding characters. Some formats, like email (MIME), also insert a line break every 76 characters, adding a little more. A 300 KB image becomes roughly 400 KB as Base64. That overhead is why you should embed only small files as Base64 and serve larger ones as normal files.

Base64 is not encryption

Base64 has no key and no secret. Anyone can decode it instantly with any tool or a single line of code. It hides data from a casual glance at best. Never use Base64 to protect passwords, API keys or personal data. HTTP Basic authentication, for example, sends the username and password as Base64, which is why it must only be used over HTTPS. If you need confidentiality, use real encryption; if you need to check integrity, use a hash or a signature.

Base64url: the URL-safe variant

The characters + and / have special meanings in URLs and file names. Base64url, also defined in RFC 4648, replaces them with - and _ and often drops the = padding. It is used in JSON Web Tokens, in URL parameters and in many web APIs. Our decoder accepts both variants: it converts - and _ back to + and / before decoding.

Common uses

  • Data URIs that embed small images, icons or fonts directly in HTML or CSS, such as data:image/png;base64,iVBORw0KGgo...
  • Email attachments, which MIME encodes as Base64 text.
  • Binary values inside JSON or XML, which have no native byte type.
  • Tokens and identifiers, including the three parts of a JWT.
  • Copying small binary blobs through text-only channels such as terminals or chat.

How to encode and decode Base64

  1. Open the Base64 encoder / decoder.
  2. Choose Encode to turn text into Base64, or Decode to turn Base64 back into text.
  3. Paste your input. Text is encoded as UTF-8, so accented letters, other alphabets and emoji work correctly.
  4. Copy or download the result.

When decoding, spaces and line breaks in the input are ignored. If the decoded bytes are not valid UTF-8 text, for example because the Base64 represents an image or a ZIP file, the tool tells you instead of showing garbled characters.

Base64 encoder / decoderEncode or decode Base64 text locally in your browser.

Images and Base64

To embed an image in HTML, CSS or JSON, the Image to Base64 tool turns an image file into a data URI you can paste directly. Going the other way, Base64 to image turns a Base64 string or data URI back into an image you can view and download. Use this for icons and small graphics; for photos, a regular image file is smaller and can be cached by the browser.

Image to Base64Encode an image as a Base64 data URI for HTML or CSS.

How to recognize Base64

Base64 text has a few telltale signs that help when you find an unknown string in a log, a config file or an API response:

  • It contains only letters, digits, + and /, or - and _ for Base64url.
  • Standard Base64 length is a multiple of four, often ending in = or ==.
  • Some prefixes are recognizable: eyJ is the start of encoded JSON, iVBORw0KGgo starts a PNG image, /9j/ starts a JPEG and JVBERi0 starts a PDF.
  • Data URIs announce it directly with ;base64, before the data.

A string can look like Base64 by accident, since ordinary words such as Test are valid input too. Decoding and checking whether the result makes sense is the reliable test.

Base64 versus URL encoding

Base64 and URL (percent) encoding solve different problems. URL encoding escapes only the characters that are unsafe in a URL, such as spaces becoming %20, and leaves the rest readable. Base64 rewrites every byte. For putting text in a query string, use URL encoding; for carrying binary data in text, use Base64 or Base64url.

Find your next tool
↑ ↓ · Enter ↵Esc · Close search