Base64 Encoder/Decoder
Encode text or files to Base64 or a data URL, and decode Base64 back to text, an image preview or a file. URL-safe supported.
Encode text or files to Base64 or a data URL, and decode Base64 back to text, an image preview or a file. URL-safe supported.
Turns text or files into a Base64 string, or turns a Base64 string back into the original.
Choose encode or decode.
Type or paste your content.
Copy the result.
No. It is only an encoding that turns data into text, and anyone can reverse it. It must not be used to keep secrets.
Yes. You can convert a file to Base64 or a data URL, and check images with a preview. All processing happens only inside the browser.
It is used when binary data such as an image or file must be turned into a string made only of text characters. Typical examples are email attachments, putting a file inside JSON, and data-URL images in CSS and HTML. Keep in mind that the size grows by about one third compared with the original.
Base64 is a conversion anyone can reverse once they know the rule, so it offers no security. Do not use it to hide passwords or personal data. When using it in a URL or file name, characters such as + and / can cause problems, so use the URL-safe form where they are replaced with - and _.
Base64 splits the original data into 3-byte (24-bit) pieces, divides each piece into four 6-bit chunks, and turns each chunk into one of 64 characters (A–Z, a–z, 0–9, +, /). That is why the result is about 33% longer than the original. If the data doesn't divide evenly into 3 bytes, "=" is added at the end to make up the length.
As the name says, it uses only 64 safe characters, so binary data can be carried in places that can only exchange text, such as email, JSON and URLs.
Typical uses are email attachments (MIME), data URIs that put an image inside a document (data:image/png;base64,…), the first two parts of a JWT token, and the HTTP basic authentication header. It is also used to put a small icon straight into CSS or HTML and cut down the number of requests.
However, putting a large image in as Base64 makes the file bigger and it can't be cached, so the page gets slower. Use it only for small files of a few KB or less, and upload larger files as normal files and load them by address.
Korean text and emoji take several bytes per character, so if the way the text was turned into bytes (UTF-8 and so on) doesn't match, it looks broken when decoded. Whatever you encode with this tool has to be decoded the same way.
The "+" and "/" in standard Base64 have special meanings in URLs, so for addresses the URL-safe version that swaps them for "-" and "_" is used. JWT is the classic example. When decoding fails, first check for these variant characters and for whether the trailing "=" is present.
Base64 represents 3 bytes with 4 characters, so the size grows by about 33 percent.
For example, a 3,000-byte file becomes 4,000 characters, and if the length is not a multiple of 3, padding characters (=) are added at the end.
0
1
2
Korean text is first turned into UTF-8 bytes and then into Base64, so 안녕 becomes 7JWI64WV.
One Hangul character is 3 bytes in UTF-8, so two characters are 6 bytes, which become 8 Base64 characters.
This is also why JavaScript's btoa function throws an error when given Korean text directly. This tool converts the text to UTF-8 before processing.
If the result differs from another site or program, first check that the text encoding is UTF-8.
URL-safe is a variant that replaces some characters so the value does not break when placed in a URL.
The plus and slash of standard Base64 have special meanings in URLs, so they are replaced with a hyphen and an underscore, and the padding is sometimes omitted.
62nd character
63rd character
Trailing =
Mainly used for
Most cases involve stray spaces or line breaks, a truncated string, or a mix of URL-safe and standard characters.
Even if you paste a data URL, this tool reads the prefix and works out the file type.
For very small images it reduces the number of requests, which helps, but for large images it costs you in size and caching.
An image embedded as Base64 is part of the HTML or CSS file, so it is not cached separately after the first download and the file size grows by 33 percent.
Base64 is not encryption, so it must not be used to keep secrets.
Anyone can turn it back into the original text with a tool like this one.
The username and password in HTTP basic authentication are also sent as Base64, but that hides nothing and is safe only together with an encrypted connection such as HTTPS.
Do not assume tokens or passwords are safe just because they were converted to Base64.
All three represent binary data as text, and the length depends on how many kinds of characters they use.
Hex (hexadecimal)
Base32
Base64
Email follows rules from the era when only text could be transmitted, so attachments are converted to Base64 for sending.
In this case a format that breaks lines every 76 characters is used so that no single line gets too long.
A JWT represents its header and payload in URL-safe Base64, and because anyone can read it, you must not put sensitive information in it.
Yes. Drag a file in to create Base64 and a data URL, and you can also save the decoded result back as a file.
Text and files you enter are processed only inside the browser and are never sent to a server.
Base64 splits 3 bytes (24 bits) into four 6-bit groups and converts each into one of 64 characters.
Man is the bytes 4D 61 6E, which in bits is 010011 010110 000101 101110. These map to the 19th, 22nd, 5th and 46th characters, T, W, F and u, giving TWFu.
0 to 25
26 to 51
52 to 61
62
63
A data URL puts the file content directly inside the address, in the form data:type;base64,content.
For example, it looks like data:image/png;base64,iVBOR... and can be placed directly in an image tag's src or CSS url().
When you add a file, this tool also creates this form, and shows an image preview from a pasted data URL.
You can roughly tell the file type from the first bytes of the decoded data.
iVBORw0KGgo
/9j/
R0lGOD
JVBERi0
UEsDB
This tool works out the format of the decoded content itself, showing a preview for images and a save button for files.
In most web and programming environments one line is correct, and only older formats such as email split it into lines.
The MIME format used in email splits lines at 76 characters or fewer, and PEM certificates split at 64 characters.
Most decoders ignore stray line breaks, but some strict tools may produce an error.
Each language has its own functions, but remember that they work on bytes, not on strings.
JavaScript (browser)
Python
Java
Linux command
The browser's btoa fails on characters such as Korean text, so you first need to convert to UTF-8 bytes.
Base64 is not suitable when size matters or when security is the goal.
Even for the same data, the string can differ depending on padding and URL-safe mode, so match the format before comparing.
Base64 is case-sensitive, so a single difference in case makes it completely different data.
When using a small icon as a background image, you can write it as background-image: url(data:image/png;base64,...).
Drag the image into this tool to create the data URL, then copy and paste it as it is.
However, images larger than a few kilobytes are faster as separate files that use the browser cache.
Base64 is used when binary data has to be carried through an environment that handles only text.
Email attachments
Data URLs
JWT
HTTP basic authentication
APIs
The result depends on whether the input is text or a file, so first check the input method.
Invisible spaces or line breaks in the text are also encoded and change the result, and mixing in Korean text increases the bytes per character and makes the result longer.