Base64 Encode / Decode

Encode text to Base64 or decode Base64 to text with full UTF-8 support. Supports URL-safe Base64 and converting files to Base64.

Convert a file to Base64

How to encode or decode Base64

  1. Choose Encode to turn text into Base64, or Decode to turn Base64 back into text.
  2. Type or paste into the top box; the result appears as you type. Tick URL-safe Base64 if the result will go into a URL, a file name or a token.
  3. Click Copy, or ⇅ Swap to move the result into the input and reverse the direction – a quick way to check that a value round-trips correctly.

Text is converted to UTF-8 bytes before encoding, so accented letters, Chinese, Japanese, Korean, Arabic and emoji all work. The decoder is forgiving: it ignores line breaks and spaces, accepts input with or without = padding, understands both the standard and the URL-safe alphabet, and strips a data:…;base64, prefix. If the decoded bytes are not valid UTF-8 text, the tool tells you how many bytes it found and what kind of file they look like (PNG, JPEG, GIF, WebP, PDF or ZIP), previews images, and offers Download decoded file.

Converting a file to Base64

Use the second panel to pick a file. Its Base64 appears straight away, along with the file name, its size and the length of the Base64 output. With Include the data URL prefix ticked, the output starts with something like data:image/png;base64,, ready to paste into an HTML src attribute or a CSS url(); untick it to get the bare Base64. The file type in the prefix is the one your browser reports, or application/octet-stream if it doesn't know. The file is read by the browser itself and never uploaded.

How Base64 works

Base64 takes the input three bytes (24 bits) at a time and splits them into four groups of 6 bits. Each 6-bit value, from 0 to 63, is written as one character of the alphabet A–Z (0–25), a–z (26–51), 0–9 (52–61), + (62) and / (63). The classic example is the word Man: its bytes 01001101 01100001 01101110 regroup into 010011 010110 000101 101110, which are 19, 22, 5 and 46 – the characters TWFu.

When the input length isn't a multiple of three, the last group is padded: Ma encodes to TWE= and M to TQ==. Every 3 bytes become 4 characters, so Base64 is about a third larger than the original: 100 bytes become 136 characters, 1,000 bytes become 1,336. The alphabet, the padding and the URL-safe variant are all defined in RFC 4648. Email (MIME) additionally breaks Base64 into lines of at most 76 characters; this tool produces one unbroken line but happily decodes wrapped input.

Examples

TextUTF-8 bytesBase64URL-safe
Hello5SGVsbG8=SGVsbG8
Hello, World!13SGVsbG8sIFdvcmxkIQ==SGVsbG8sIFdvcmxkIQ
café5Y2Fmw6k=Y2Fmw6k
你好65L2g5aW95L2g5aW9
😀48J+YgA==8J-YgA
<<???>>7PDw/Pz8+Pg==PDw_Pz8-Pg

URL-safe Base64 (base64url)

In a URL, + can be read as a space and / separates path segments, and = has a meaning in query strings. The URL-safe alphabet replaces + with - and / with _, and the padding is usually dropped, as the last row of the table shows. JSON Web Tokens use this variant for all three of their parts. When decoding you don't need to say which variant you have; both are recognised.

Where you'll meet Base64

  • Data URLs embed small images and fonts directly in HTML or CSS.
  • Email attachments are sent as Base64 inside the message.
  • HTTP Basic authentication sends username:password in Base64. The standard's own example, Aladdin:open sesame, becomes QWxhZGRpbjpvcGVuIHNlc2FtZQ== – which also shows why Basic authentication is only safe over HTTPS.
  • APIs and JSON use Base64 to carry binary data such as images, signatures and keys inside text fields.

Some prefixes are worth recognising: iVBORw0KGgo is the start of every PNG file, /9j/ a JPEG, JVBERi0 a PDF, and eyJ usually a JSON object, such as the header of a JWT.

When decoding goes wrong

  • “Contains characters that are not used in Base64” – often stray quotes or punctuation copied along with the value. If the string came from a URL and contains %3D or %2F, decode it with URL Encode / Decode first.
  • “Invalid length” – part of the string is missing, usually because it was cut off while copying.
  • Binary data instead of text – either the data really is a file, or it is text saved in an older encoding such as Latin-1: é in Latin-1 is the single byte 6Q==, which is not valid UTF-8. Word and Excel files (.docx, .xlsx) are ZIP containers, so they are offered as decoded.zip; rename the file to its proper extension.

FAQ

Is Base64 a form of encryption?

No. It is a reversible encoding with no key; anyone can decode it in a second. Never rely on it to hide passwords or personal data.

Why does my output end with = or ==?

That is padding: one = when the input length leaves 2 bytes over, two when it leaves 1. It tells a decoder how many bytes the last group contains.

Can I decode a JWT here?

You can decode each of the three dot-separated parts separately, but the JWT Decoder splits the token for you and shows the header and payload as formatted JSON, with readable dates.

How large a file can I convert?

The limit is your browser's memory. Bear in mind that data URLs are best for small assets: a large image embedded as Base64 makes the page a third heavier and can't be cached separately from it.