devtools.cihat.dev

Base64 decode and encode online

Paste Base64 to decode it back into text, an image or a PDF, or turn text and any file into Base64. Everything happens in your browser; nothing is uploaded.

What to do

Result

The result appears here as you type.

How to use it

  1. Pick Base64 to text or file to decode, or Text to Base64 or File to Base64 to encode.
  2. Type, paste or drop your input. The result updates as you go. Line breaks and spaces inside pasted Base64 are ignored, and a whole data: URI is accepted.
  3. Copy the result or download it. A decoded image shows a preview; a decoded PDF or archive downloads with the right extension.

How Base64 works

Base64 is defined in RFC 4648. It reads the input three bytes (24 bits) at a time and writes those bits as four characters of 6 bits each, picked from 64 safe characters: A–Z, a–z, 0–9, + and /. When the input does not divide into groups of three, the last group is padded with =.

So every 3 bytes become 4 characters, and the output is 4 × ⌈n ÷ 3⌉ characters long: about a third larger than the input. A 30 KB image becomes 40 KB of text. That is the cost of letting binary data travel through places that only accept text, such as JSON, e-mail, HTML attributes and environment variables.

Base64 is an encoding, not encryption. There is no key: anyone can decode it, exactly as this page does. Never use it to hide a password or an API key.

The test vectors from RFC 4648, section 10
InputBytesBase64
f1Zg==
fo2Zm8=
foo3Zm9v
foob4Zm9vYg==
foobar6Zm9vYmFy

Base64 to image, PDF or file

Paste Base64 or a whole data URI (RFC 2397) such as data:image/png;base64,iVBORw0KGgo… in the decode mode. The tool reads the first decoded bytes, the file’s signature, to recognise PNG, JPEG, GIF, WebP, AVIF, PDF, ZIP, MP3 and MP4. Images appear straight away; Download saves the file with the right extension. If the bytes are valid UTF-8, they are shown as text instead.

Because the signature is always at the start of a file, the first characters of the Base64 already tell you what it is:

  • iVBORw0KGgo is a PNG image (bytes 89 50 4E 47 0D 0A 1A 0A).
  • /9j/ is a JPEG image (bytes FF D8 FF).
  • R0lGOD is a GIF image (GIF8).
  • JVBERi0 is a PDF (%PDF-).
  • UEsD is a ZIP archive. .docx, .xlsx and .apk files start the same way, because they are ZIP archives inside.
  • eyJ is a JSON object starting with {". Three of these joined by dots are a JWT: read it with the JWT decoder.

URL-safe Base64 and padding

Standard Base64 uses + and /, which have meanings inside URLs and file names. The URL-safe variant, base64url (RFC 4648, section 5), uses - and _ instead. The bytes FB FF are +/8= in standard Base64 and -_8 in base64url. JWTs use base64url and drop the = padding (RFC 7515). This decoder accepts both alphabets, with or without padding.

Padding is predictable: one = when the last group had two bytes, two when it had one. A length that leaves a single character in the last group of four is impossible, which is why the tool says the string was cut short.

Base64 on the command line and in code

The same conversion in the tools you already have. GNU base64 wraps encoded output after 76 characters, the MIME line limit from RFC 2045; add -w 0 for one line.

WhereEncodeDecode
Linux, macOSbase64 file.pngbase64 -d file.txt
Pythonbase64.b64encode(data)base64.b64decode(text)
JavaScriptbtoa(text)atob(text)

Text, UTF-8 and btoa

Text has to become bytes before it can become Base64, and this tool uses UTF-8, so Turkish, Arabic, Chinese and emoji survive the round trip: Çağrı encodes to w4dhxJ9yxLE=. The browser’s own btoa() throws an InvalidCharacterError on any character outside a single byte, which is the usual reason a hand-written encoder fails on ş or €.

If decoding gives garbled letters, the source text was probably encoded from another character set, such as Windows-1254. If the decoded text is JSON, format it in the JSON formatter. To put Base64 inside a query string, percent-encode it with the URL encoder first, because + and / change meaning there.

Questions people ask

How do I decode Base64?

Choose Base64 to text or file and paste the string. Text appears at once; an image shows a preview; any other file downloads with the right extension.

How do I convert Base64 to an image or a PDF?

Paste it in the decode mode. The tool recognises the file from its first bytes, shows images and saves the PDF or image with the right extension when you press Download.

Is my file uploaded?

No. Encoding and decoding run in your browser with JavaScript. The file never leaves your device.

Why does decoding say the length is not possible?

Valid Base64 never leaves a single character in its last group of four. That usually means the string was cut off when it was copied.

Why does my Base64 end with = or ==?

That is padding. The input length was not a multiple of three bytes, so the last group of four characters is filled with one or two = signs.

Is Base64 encryption?

No. It only changes how bytes are written. Anyone can decode it without a key.

How much bigger does Base64 make a file?

About a third: every 3 bytes become 4 characters, so 300 KB becomes 400 KB, plus line breaks if the encoder wraps lines.