tools / base64
base64/
Convert text, files and images to and from Base64. UTF-8, with URL-safe support.
Plain text
Base64
What is Base64
Base64 is the encoding defined in RFC 4648 that writes every 3 bytes (24 bits) as 4 characters from the alphabet A-Z, a-z, 0-9, + and /. This page encodes text (as UTF-8) and files, supports the URL-safe form, and decodes back to text, images or files.
How it works: one alphabet lookup per 6 bits
- Text is first converted to bytes as UTF-8; when you pick a file, its raw bytes are used directly.
- Every 3 bytes make 24 bits, which are cut into 4 groups of 6 bits; each group is a number from 0 to 63.
- Each number becomes a character: 0 to 25 are A to Z, 26 to 51 are a to z, 52 to 61 are 0 to 9, 62 is + and 63 is /.
- If 1 byte is left at the end it becomes 2 characters plus 2 = signs; if 2 bytes are left they become 3 characters plus 1 = sign.
- The URL-safe form (RFC 4648 section 5) replaces + with - and / with _; this page also drops the trailing = signs.
Example
English letters, the comma and the space take 1 byte each and the two Chinese characters 3 bytes each, 13 bytes in all; 13 divided by 3 leaves 1, so the result ends with 2 = signs:
- Input
- Hello, 世界
- Output
- SGVsbG8sIOS4lueVjA==
URL-safe form: the + and / of the standard form become - and _, with no = at the end:
- Input
- <<???>>
- Output
- PDw_Pz8-Pg
Sources
FAQ
What if decoding says "Contains non-Base64 characters" or "Invalid length"?
Check that the text is complete and clean. The accepted characters are A–Z, a–z, 0–9, + and /, plus - and _ from the URL-safe form, and = may only appear at the end; spaces, line breaks and a leading data:...;base64, are ignored automatically. Full-width symbols, quotation marks and leftovers of URL encoding such as %2B trigger "Contains non-Base64 characters", while "Invalid length" usually means some characters were lost when copying.
What if decoding says "Not UTF-8 text" or the result is garbled?
The decoded bytes are not UTF-8 text. Usually the original used another encoding such as GBK, or the data is binary to begin with, like an image, an archive or encrypted bytes. This tool only displays UTF-8 text and will not force other encodings into garbled characters. For binary data, click "Download file" to save it; GBK text needs a tool that can convert from GBK.
Why does my result differ from JavaScript, Python or the command line?
The usual causes are a trailing newline or a different character encoding. This tool encodes exactly what is in the box as UTF-8, without trimming spaces or line breaks, while echo on the command line adds a newline at the end by default, so use echo -n to match. For Chinese text and emoji, make sure the other side also uses UTF-8: JavaScript's btoa throws an error on them directly, and in Python you must encode('utf-8') before b64encode.
Can I drop the = at the end, and when should I use the URL-safe form?
Decoding works without the = signs too; this tool adds them back automatically. Whether you can leave them out depends on the receiver, since some libraries require them. Use "URL-safe" when the result goes into a URL parameter or a file name; JWT uses this form. When decoding, - and _ are recognised automatically, so no extra switch is needed.
Is there a size limit when converting a file to Base64?
Yes, a single file can be at most 20 MB, and larger ones are rejected with a message. By default the output is a Data URL with a prefix such as data:image/png;base64, which you can drop straight into a web page's image address or CSS; if you only want the plain Base64, delete everything up to and including the comma. Base64 makes the data about one third larger, so embedding large images is not recommended.
How do I turn Base64 back into an image or a file?
Switch to "Decode" and paste the Base64 or a full Data URL. Images (PNG, JPEG, GIF, WebP) get a preview, text is shown directly, and other binary data only shows its size. In every case you can click "Download file" to save the result: images are named by format, and everything else is saved as decoded.bin, so rename the extension yourself if needed.
Is Base64 encryption? Can it keep data secret?
No. Base64 only rewrites bytes as printable characters, and anyone can reverse it; there is no key and no secrecy. If you need confidentiality, use a real encryption algorithm such as AES.
Are my text and files uploaded?
No. Encoding and decoding happen in your browser, and a file you pick is only read on your own device, never sent to a server.