Toolstia / Base64 encoder and decoder
Encode and decode Base64
Base64 shows up whenever binary or awkward text has to travel through a system that only handles plain characters: email attachments, data URLs, API tokens, HTTP Basic authentication headers, and configuration values. This tool converts text to Base64 and back, with an option for the URL-safe variant used in tokens and web addresses.
Characters from any language and emoji are handled by converting the text to UTF-8 first, so what you decode is exactly what you encoded. The tool works on text; it is not a file converter, and the conversion runs in your browser rather than on a server. Because the result updates as you type, it is also a quick way to check what a token, header or encoded setting really contains.
Base64 is an encoding, not encryption. Anyone can decode it, so never use it to hide passwords.
How it works
- Choose encode or decode.
- Paste your text or Base64 string.
- Copy the result, or use Swap to run it back the other way.
What Base64 is
Base64 writes binary data using 64 plain characters so it can travel safely in emails, URLs and JSON. It makes data about a third bigger.
URL-safe Base64
Standard Base64 uses + and /, which have special meaning in web addresses. The URL-safe form uses - and _ instead and leaves off the = padding. Decoding accepts both forms.
Unicode text
Text is converted to UTF-8 before encoding, so emoji and characters from any language round-trip correctly.
Not encryption
Base64 only changes the format. Anyone can decode it, so it does not protect secrets.
How the encoding works, with real output
Base64 takes the data three bytes at a time, splits those 24 bits into four groups of 6 bits, and writes each group as one of 64 characters: A-Z, a-z, 0-9, plus and slash. When the length is not a multiple of three, equals signs pad the end. You can see it in the shortest inputs: a becomes YQ==, ab becomes YWI=, and abc becomes YWJj with no padding.
Hello encodes to SGVsbG8=. Output length is 4 times the input length divided by 3, rounded up, which is why 100 bytes become 136 characters. That roughly one-third growth is the price of using only safe characters.
Standard versus URL-safe output
Standard Base64 uses plus and slash, both of which have a meaning in web addresses and file paths. The URL-safe form swaps them for hyphen and underscore and drops the equals padding. Take an input of three question marks followed by three greater-than signs. Standard output is Pz8/Pj4+, while URL-safe output is Pz8_Pj4-.
JSON Web Tokens use this URL-safe form. The payload {"sub":"123"} encodes to eyJzdWIiOiIxMjMifQ with no padding, and that string is what you would see in the middle part of a token. The decoder accepts either alphabet and does not require the padding, so you can paste a token segment straight in.
Typical uses, and a real one to try
HTTP Basic authentication sends username:password as Base64. The pair user:pass becomes dXNlcjpwYXNz, which is sent in an Authorization header after the word Basic. This is a good illustration of why Base64 is not protection: anyone who sees the header can decode it in a second.
Other uses include embedding small text in a data URL, storing a multi-line value in a single-line environment variable, and reading the readable parts of a token while debugging. For secrets that matter, use encryption and transport security instead.
Why decoding sometimes fails
The decoder removes spaces and line breaks first, so text that was wrapped at 76 columns by an email system decodes fine. It then requires the remaining characters to be from the Base64 alphabet, with at most two equals signs at the very end. A stray comma, quote or colon causes the not valid Base64 message.
A common trap is a data URL. If the value starts with data:image/png;base64, delete everything up to and including the comma and paste only the part after it. Another is decoding an image or archive: the bytes are valid, but they are not UTF-8 text, so the tool says the decoded data is not readable text rather than printing garbage.
What this tool does not do
There is no file upload or download here, so you cannot turn an image into a data URL or restore a file from Base64. Only text is processed. Line wrapping is not added on output either, so a very long result is a single line.
Text is always handled as UTF-8. If the Base64 was made from text in an older encoding, such as Windows-1252 or Shift JIS, decoding may fail the readable-text check or show wrong characters.
Questions
Is my text uploaded?
No. Encoding and decoding run in your browser.
Can I decode an image or file?
This tool decodes text. If the decoded data is not readable text, you will see a message saying so.
Why does decoding fail?
The input has characters that are not part of Base64, or it was cut off. Spaces and line breaks are ignored.
Why does my encoded text end with equals signs?
They are padding. When the input is not a multiple of three bytes, one or two equals signs fill the last group. URL-safe mode leaves them off, and most decoders, including this one, work without them.
Can two different inputs give the same Base64?
No. Encoding is reversible, so every distinct input has a distinct output. That is the main difference from a hash.
Is Base64 a way to compress text?
No, it makes data about a third larger. If you need smaller data, compress it first and then encode the result if you must send it as text.
Why does the same word give different Base64 in different tools?
Usually the text encoding differs, or one tool adds a line break, trailing newline or padding style. This tool encodes exactly what you typed as UTF-8.
Does the Swap button change the direction?
Yes. It moves the result into the input box and switches between encode and decode, so you can check a round trip in one click.