What the Base64 Encoder & Decoder does
The tool has an input box on the left and a result box on the right, with Encode and Decode buttons and a Copy button on the result. Encode converts your text to UTF-8 bytes with TextEncoder and then to Base64 with btoa, using the standard alphabet of A to Z, a to z, 0 to 9, + and /, with = padding at the end. The output is one unbroken line. Hello, world! becomes SGVsbG8sIHdvcmxkIQ== and café becomes Y2Fmw6k=.
Decode strips every space, tab and line break from the text, decodes the Base64 with atob and then interprets the bytes as UTF-8 in strict mode. If the characters are not valid Base64, or the decoded bytes are not valid UTF-8, the tool reports This is not valid UTF-8 Base64 text instead of showing replacement characters. That strictness is deliberate: the page is for text, and a silent wrong answer would be worse than an error.
The UTF-8 step is what separates this from the naive btoa call found in old snippets. btoa accepts only characters whose code is below 256 and throws an InvalidCharacterError for anything else, so a direct call fails on Arabic, Chinese, curly quotes and emoji. Converting to bytes first means any text encodes, and the receiving side can decode it with any UTF-8-aware Base64 library.
Base64 is a transport encoding, not encryption and not compression. Anyone can reverse it in a second and the result is about a third larger than the input. Use it where only text is allowed, such as an Authorization header, a JSON field that must carry bytes or a data URL, and keep secrets protected by real encryption.
How to use it
Paste the text or the Base64
Plain text to encode, or a Base64 string to decode. Line-wrapped Base64 copied from an email or a certificate file is fine; the whitespace is removed before decoding.
Press Encode or Decode
The result appears in the box on the right and a message confirms which direction ran. Your input is never changed, so if decoding fails you can inspect it exactly as pasted.
Copy the result
Copy puts the result on the clipboard. There is no download button and no file picker; for an image file, use the Image to Base64 tool instead.
What the encoder produces
The output follows section 4 of RFC 4648: each group of three bytes becomes four characters from the 64-character alphabet, and when the byte count is not a multiple of three the last group is padded with one or two = signs so that the length is always a multiple of four. Every character of your text is first turned into one to four UTF-8 bytes, so a string of accented or non-Latin characters produces more Base64 than the same number of ASCII letters.
The alphabet is the standard one with + and /. The URL-safe variant from section 5 of the RFC, which uses - and _ so that the value can sit inside a URL or a JWT, is not produced here. If you need that form, replace + with - and / with _ in the output; the padding can usually be dropped as well, since most URL-safe decoders accept its absence.
What the decoder accepts
Decoding uses the browser's forgiving algorithm from the WHATWG Infra standard. All ASCII whitespace is removed first, so Base64 wrapped at 76 characters by an email client or split across lines in a config file decodes without editing. Padding may be omitted entirely: YQ decodes to a just as YQ== does. Padding that is present but wrong, such as YQ= with a single sign, is rejected, as is any character outside the alphabet, including the - and _ of the URL-safe form.
After the bytes are recovered they are decoded as UTF-8 with the fatal flag set. A byte sequence that is not UTF-8, which is what you get from a Base64-encoded image, PDF, ZIP or a string encoded in Windows-1252, fails at this point. The error message is the same in both cases, so when correct-looking Base64 is rejected, the usual explanation is that it never contained text.
- Accepted: standard alphabet, with or without padding, with whitespace anywhere
- Rejected: - and _ (URL-safe alphabet), partial padding, stray punctuation
- Rejected after decoding: bytes that are not valid UTF-8 text
Where Base64 belongs and where it does not
Base64 exists so that binary data can travel through channels designed for text: email bodies, HTTP headers, JSON and XML documents, data URLs, command-line arguments. An HTTP Basic Authorization header is the username, a colon and the password encoded this way, and this tool will produce or decode one. It is also a quick way to check what a token or a cookie value contains, provided it is text.
It is not a security measure. The encoding is public, reversible and recognisable at a glance by the trailing = signs, so a Base64 password in a config file is a plain-text password with extra steps. It is not compression either; the output is always larger than the input, which is one reason to keep embedded images small.
Limits to know before you rely on it
- Decoding is for text only. Base64 that represents an image, PDF or other binary data fails the UTF-8 check with an error rather than offering a download.
- The URL-safe alphabet with - and _ is neither produced when encoding nor accepted when decoding; swap the characters by hand for JWT-style values.
- Output is one unbroken line. MIME email bodies that need a line break every 76 characters must be wrapped elsewhere.
- Base64 with missing padding decodes, but text with the wrong number of = signs or with stray characters is rejected as a whole; there is no partial recovery.
- There is no file picker and no download; the box holds text only, and pasting many megabytes can make the page slow.
Questions people ask about the Base64 Encoder & Decoder
The Base64 looks correct, so why does decoding say it is not valid UTF-8 Base64 text?
Because the decoded bytes are not text. A Base64 string that holds an image, a PDF, a compressed file or a binary token passes the Base64 step and then fails the UTF-8 check. Text encoded in another character set, such as Windows-1252, fails the same way. Decode those with a tool that writes bytes to a file or lets you pick the encoding.
Does the encoder handle emoji and non-Latin alphabets?
Yes. Text is converted to UTF-8 bytes before encoding, so every character works. The grinning face emoji encodes as 8J+YgA== and the two characters 日本 encode as 5pel5pys. Any decoder that treats the bytes as UTF-8 will restore the original text.
Why does the output end with one or two = signs?
They are padding. Base64 writes three bytes as four characters, so when the input length is not a multiple of three the final group is completed with = signs to keep the output a multiple of four. One sign means two bytes were left over, two signs mean one byte was. Input that is a multiple of three bytes long has no padding at all.
Can I decode a JWT or another URL-safe Base64 value here?
Not directly, because the URL-safe alphabet uses - and _ which the decoder rejects. Replace every - with + and every _ with / and decode the result; padding may be left out. A JWT has three such segments separated by dots, and the first two decode to JSON text while the third is a binary signature that will fail the UTF-8 check.
Is Base64 a safe way to store a password or an API key?
No. Base64 is reversible by anyone who sees it and is easy to recognise. Anything Base64 in a repository, a log or a config file should be treated as exposed. Use a secrets manager or real encryption for credentials and keep Base64 for its intended job of carrying bytes through text.
Will line breaks in copied Base64 break decoding?
No. Spaces, tabs and line breaks are removed before the decoder runs, so Base64 wrapped by an email program, a PEM file or a chat message decodes as if it were one line. Characters that are not whitespace and not part of the alphabet, such as quotes around the value, do cause an error and need removing.
Sources and further reading
- RFC 4648, The Base16, Base32, and Base64 Data Encodings: the standard alphabet, padding rules and the URL-safe variant
- MDN Web Docs, Window.btoa(): why btoa alone fails on characters above 255 and how the UTF-8 conversion avoids it
- WHATWG Infra Standard, forgiving-base64 decode: the whitespace and padding rules the browser applies when decoding
- MDN Web Docs, TextDecoder() constructor: the fatal option that makes invalid UTF-8 an error instead of replacement characters