Maaz Zindani

Loading the index…

↑↓ move↵ openesc close3993 pages

Free tool · Developer tools

Base64 decode and encode

Paste a Base64 string to read it as text, or paste text (or choose a file) to turn it into Base64. Nothing you enter leaves your device.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Direction
Result
Hello, world!
  • Decoded as UTF-8 text
Input
20 characters
Output
13 bytes

How to use the Base64 Encoder Decoder

  1. Pick Decode Base64 or Encode to Base64 under Direction.
  2. Paste into Your text or Base64, or use Or choose a file. The file is read on your device.
  3. When encoding, tick URL-safe (- and _) for the - and _ alphabet, and untick Keep = padding to drop the trailing equals signs.
  4. Read the Result, then use Copy or Download. A message in red tells you what is wrong with the input.

How do I decode a Base64 string?

Choose Decode Base64 and paste the string. The tool ignores spaces and line breaks, accepts a leading data:...;base64, prefix, and does not insist on the trailing = signs. So SGVsbG8sIHdvcmxkIQ== and SGVsbG8sIHdvcmxkIQ both give "Hello, world!".

Base64 turns bytes into 64 safe characters. RFC 4648 lists them as A to Z, a to z, 0 to 9, then + and /. The decoder reverses the encoding and then reads the bytes as UTF-8 text, which is why aMOpbGxvIOKCrA comes out as "héllo €" and not as garbled characters. The string has 14 characters for 10 bytes, because é and € take more than one byte each in UTF-8.

If the bytes are not valid UTF-8 text, for example an image, a PDF or a compressed file, the tool says so and shows the size instead of printing nonsense. Press Download to save the raw bytes. To decode a whole file of Base64, choose it under Or choose a file while in decode mode and its text is loaded into the box.

How does Base64 encoding work, step by step?

Base64 reads the data three bytes (24 bits) at a time and splits each group into four pieces of 6 bits. Each piece is a number from 0 to 63, and each number picks one character from the alphabet. RFC 4648 puts it this way: every 24-bit group becomes 4 characters. That is why the output is about one third longer than the input: 13 bytes of "Hello, world!" become 20 characters.

When the data does not fill the last group, the encoder adds the pad character = so the length is a multiple of 4. One leftover byte gives two characters and ==. Two leftover bytes give three characters and one =. A multiple of 3 bytes needs no padding. The table shows each case, encoded by this tool.

Text, its UTF-8 size and its Base64 form
TextBytesBase64CharactersPadding
M1TQ==42 (==)
Ma2TWE=41 (=)
Man3TWFu4none
Hello5SGVsbG8=81 (=)
Hello, world!13SGVsbG8sIHdvcmxkIQ==202 (==)
héllo €10aMOpbGxvIOKCrA==162 (==)
user:pass9dXNlcjpwYXNz12none

The Characters column is always 4 times the bytes divided by 3, rounded up. Read it backward to guess the size of the original: a string of 20 characters with one = holds 14 bytes.

What is URL-safe Base64, and why does my string end in =?

The + and / characters have special meanings in URLs and file names. The URL-safe variant, called base64url in section 5 of RFC 4648, uses - and _ in their place. The bytes FB FF FE show the difference: standard Base64 gives +//+ and URL-safe gives -__-. The decoder detects which form you pasted and says so in the result. A string that mixes + or / with - or _ is reported as an error, because it cannot be valid in either form.

The = signs are the padding described above. Section 3.2 of the RFC says padding must be included unless the specification that uses Base64 says otherwise, and section 5 says it can be skipped when the length is known from elsewhere. That is why many tokens in URLs have no = at the end. This tool adds the padding back before decoding, and when encoding you can turn it off with Keep = padding.

How can I tell if a string is valid Base64?

Check four things. First, every character must be from A to Z, a to z, 0 to 9, + and /, or - and _ for the URL-safe form, with spaces and line breaks ignored. Second, the = signs may only appear at the end, at most two of them. Third, once the = signs are removed, the length cannot leave exactly one character over a multiple of 4, because one character carries only 6 bits and cannot make a whole byte. Fourth, if there are = signs, the total length must be a multiple of 4.

Here is what the tool says for three broken strings. SGVs bG8 is fine, since the space is ignored. SGVsb gives: "The length is not valid: 5 characters cannot be Base64 (a stray character was added or lost)." The text SGVs*G8= gives: ""*" at position 5 is not a Base64 character. Base64 uses A-Z, a-z, 0-9, + and / (or - and _ in the URL-safe form)." And SG=Vs gives: "The = padding can only appear at the end."

A string can pass all four checks and still decode to bytes that are not text. That is normal for images, archives and encrypted data, and the tool then shows the size and offers the bytes as a download instead of text. A string that decodes to readable text is a good sign that it was Base64 to begin with, but only the person who made it knows what it was meant to be.

Is Base64 encryption, and how do I read the errors?

No. Base64 is an encoding, not encryption: it has no key, and anyone can reverse it, as this page does. Never treat a Base64 string as a way to hide a password or token. For example dXNlcjpwYXNz is just user:pass written in Base64.

The error messages name the problem. "Not a Base64 character" gives the character and its position, which often points to a copied quote mark or a stray comma. RFC 4648 section 3.3 says implementations must reject characters outside the alphabet unless the using specification says otherwise, so this tool does the same, except for spaces and line breaks. "Length is not valid" means one character was lost or added: no Base64 string leaves exactly one character in the last group. "Padding" errors mean the equals signs are in the wrong place or number, and a string cannot have more than two.

To turn an image into Base64, choose the file while in encode mode. You get the Base64 of its bytes; add a prefix such as data:image/png;base64, yourself if you need a data URI. A file of a few megabytes makes a very long string, so use Download rather than Copy.

Use it with

Questions

How do I decode Base64 online?

Choose Decode Base64, paste the string, and the text appears under Result. For example SGVsbG8sIHdvcmxkIQ== decodes to "Hello, world!". Line breaks, missing padding and a data: prefix are handled for you.

Is Base64 encryption?

No. It is a reversible encoding with no key. Anyone can decode it, so it does not protect secrets.

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

URL-safe Base64 uses - and _ instead of + and /, and often omits the = padding. The bytes FB FF FE are +//+ in standard Base64 and -__- in URL-safe Base64.

Why does my Base64 string end in =?

The = signs pad the last group to 4 characters. One = means the last group had 2 bytes, two == means it had 1 byte. "Ma" encodes to TWE= and "M" to TQ==. They can be dropped when the length is known.

How much bigger is Base64 than the original?

Every 3 bytes become 4 characters, so about one third bigger. "Hello, world!" is 13 bytes and 20 characters in Base64.

Can it encode a file or an image?

Yes. Choose a file in encode mode. It is read with your browser's file reader on your device and never uploaded.

How this page was made: the tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations were drafted with AI help and checked against the tool's own output.