Base64 Encoder/Decoder
Free Base64 Encoder and Decoder — convert text, files, and images to Base64 encoding and back. Essential developer tool for working with REST APIs, data URIs, JWT tokens, email attachments (MIME), and embedded resources in HTML/CSS.
Overview
Base64 encoding is a cornerstone of modern data transmission, providing a robust method for converting binary data into a text-based format. This process is essential when binary data, such as images, videos, or executable files, needs to be sent over systems that are designed to handle only text. The encoding works by taking the binary data and breaking it down into 6-bit chunks. Each 6-bit chunk is then mapped to one of 64 characters from a predefined set, which typically includes uppercase letters, lowercase letters, numbers, and two special characters (+ and /). This character set is specifically chosen to be universally compatible with most text-based systems, ensuring that the data remains intact and uncorrupted during transit. The encoded output, a string of these characters, can then be safely embedded in text-based formats like HTML, XML, or JSON, or transmitted through email systems without the risk of being misinterpreted as control characters.
The technical process of Base64 encoding is a fascinating example of data manipulation for compatibility. It begins by taking a stream of binary data and dividing it into 3-byte (24-bit) groups. Each of these 24-bit groups is then further divided into four 6-bit segments. Each 6-bit segment can represent a value from 0 to 63, which corresponds to an index in the Base64 character set. The character at that index is then used to represent the 6-bit segment. If the original binary data is not a multiple of 3 bytes, padding is added to the end of the encoded output. This is done by adding one or two '=' characters to the end of the string, indicating that the original data was one or two bytes short of a full 3-byte group. This padding ensures that the encoded data can be correctly decoded back to its original binary form without any loss of information, making Base64 a reliable and reversible process.
The importance of Base64 encoding extends far beyond simple data transmission. It plays a critical role in various web technologies and security protocols. For instance, it is commonly used to embed images directly into HTML or CSS files, reducing the number of HTTP requests needed to render a page and improving performance. In the realm of security, Base64 is often used to encode credentials for HTTP basic authentication, providing a simple way to transmit usernames and passwords. It is also a fundamental component of many data URI schemes, allowing for the inclusion of data in-line in web pages. Furthermore, Base64 is used in the creation of digital signatures and certificates, where it is used to encode the binary data of the signature or certificate into a text format that can be easily stored and transmitted. Its versatility and reliability have made it an indispensable tool for developers and system administrators working with a wide range of applications and protocols.
Worked example
Embedding a 9,216-byte PNG icon in a stylesheet as a data URI
A developer has an icon PNG of 9,216 bytes that is used on one button and wants it inside the CSS file so the button paints without a second network request, and needs to know how much the stylesheet grows and what prefix to use.
- Open the Encode tab and press Load file to encode, then choose the 9,216-byte PNG. The file card shows the name, 9.0 KB and the word encoded.
- The encoder reads the bytes with the File API in 24 KB chunks, so no single call has to turn the whole file into one huge string, and nothing is uploaded.
- The output is 12,288 characters, because Base64 turns every 3 bytes into 4 characters: 9,216 divided by 3 is 3,072, times 4 is 12,288. The same arithmetic was checked against a 12,345-byte file, which the encoder returns as exactly 16,460 characters.
- That is 33.3 percent more data than the original file, and 12,288 characters is well under the 200,000 character display limit, so the value is shown in the output box rather than only offered as a download.
- Press Download to save the value, or Copy to put it on the clipboard. A file encode is offered as a download named after the original with .b64 appended, so icon.png becomes icon.png.b64.
- Paste it into the rule with the prefix: background-image: url("data:image/png;base64,PASTE"), where PASTE stands for the 12,288 characters. The prefix data:image/png;base64, is 22 characters, so the declaration carries 12,310 characters of payload.
- The stylesheet grows by roughly 12 KB and the button saves one HTTP request. Base64 is an encoding, not encryption: anyone who opens the CSS file, or the browser cache, can read the PNG bytes straight back out.
Result: A 9,216-byte PNG becomes 12,288 Base64 characters, 12,310 with the data:image/png;base64, prefix, a 33.3 percent size increase that removes one request. The same tool decodes any of those values back to the exact bytes, and the whole round trip stays in the browser tab.
How to use Base64 Encoder/Decoder
- Enter text or Base64
- Click Encode or Decode
- View result
- Copy to clipboard
Common mistakes
Treating Base64 as encryption, or as a way to hide something so that other people cannot read it.
Base64 is a reversible encoding that any decoder undoes instantly, and this tool decodes a value in one click. Anything written as Base64 in a configuration file, a URL or a database column is readable by whoever sees it, including credentials and personal data. Use file-encryptor when a file must be protected and a password manager when a secret must be stored.
Pasting a complete data URI into the decode box.
The decoder wants the Base64 payload on its own. A value that starts with data:image/png;base64, fails validation because of the colon, the semicolon, the slash and the comma, which are not part of any Base64 alphabet. Paste only what follows the comma.
Assuming that a decoded JWT payload proves anything about the token.
The tool recognises three dot-separated base64url segments and decodes the middle one as JSON, and it says plainly that the header and the signature are separate segments. It does not verify the signature, so the claims are only readable, not trustworthy: anybody can craft a token with any payload. Verify the token with the issuing service or a JWT library.
Putting a standard-alphabet Base64 value into a URL, a query parameter or a filename.
The standard alphabet contains plus and slash, which URLs and file systems reinterpret, and the padding equals signs are awkward in query strings. Switch on the URL-safe option, which emits minus and underscore and drops the padding, and remember that the decoder turns URL-safe mode on automatically when it sees a minus or an underscore in the input.
Features
- Encode/decode
- Instant conversion
- Copy to clipboard
- Special characters
Limits worth knowing
- Base64 is an encoding, not encryption, not compression and not a signature. The output is about a third larger than the input and offers no protection whatsoever.
- Files are capped at 25 MB. A larger file is reported as over the size limit because the whole thing is read into the tab memory, and the interface states the maximum as 25.0 MB.
- Inline paste is capped at 1,000,000 characters, and results above 200,000 characters are not written into the output box: the length is announced instead and the value is available only through Download. For file encoding that threshold arrives at about 150,000 bytes of input.
- Decoded bytes are always interpreted as UTF-8 text. Binary results are flagged because replacement characters appear, are useless in the text box, and have to be taken through Download, which names the file after the original minus a .b64, .base64 or .txt suffix, or decoded.txt when there is no name.
- One input at a time, with no batch mode, no archive support, no line wrapping and no progress beyond the file size and the output length: the value is emitted as one unbroken string.
When to use it
- A web developer wants to embed a small logo directly into a CSS file to reduce HTTP requests. They use a Base64 encoder to convert the image file into a string, which they then include in their stylesheet as a data URI.
- A mobile app developer needs to send a user's profile picture to a server. To ensure the image data is transmitted correctly within a JSON payload, they encode the image to Base64 before sending it.
- A system administrator needs to include a binary file in a configuration script that only accepts text. They use Base64 to encode the file, allowing them to embed it directly into their script.
- An email marketer wants to embed images in their HTML emails to ensure they are displayed correctly in most email clients. They use Base64 encoding to include the images as data URIs in the email's HTML.
- A security professional is analyzing a suspicious file and finds a long, seemingly random string of characters. They use a Base64 decoder to see if the string is hiding any malicious code or data.
- A software engineer is working with an API that returns data in a text-based format, but some of the data is binary. They use a Base64 decoder to extract the binary data from the API response.
Practical tips
- For large files, consider the 33% size increase that comes with Base64 encoding. While convenient, it can significantly increase bandwidth usage. For very large files, it may be more efficient to host the file separately and link to it instead of embedding it.
- When using Base64 for data URIs, be mindful of browser limitations. Some older browsers have limits on the length of data URIs they can handle. It is a good practice to test your implementation across different browsers to ensure compatibility.
- Do not use Base64 as a form of encryption. It is a reversible encoding process and can be easily decoded by anyone. For sensitive data, always use a strong encryption algorithm in addition to or instead of Base64 encoding.
- When decoding Base64 strings, always handle potential errors gracefully. An invalid Base64 string can cause your application to crash if not handled correctly. Use a try-catch block or a similar error-handling mechanism to manage decoding errors.
- To optimize performance, perform Base64 encoding and decoding operations on the server-side whenever possible. This will offload the processing from the client's browser, resulting in a faster and more responsive user experience, especially on mobile devices.
Why use this tool
- Safely transmit binary data across text-only systems without corruption. Base64 ensures that your images, audio files, and other binary data can be reliably sent through email, embedded in HTML, or stored in XML and JSON without being misinterpreted or altered.
- Improve web page performance by embedding images directly into your HTML or CSS files. This technique, known as data URIs, reduces the number of HTTP requests a browser needs to make, resulting in faster page load times and a better user experience.
- Ensure data integrity with a reversible encoding process. Base64 encoding is not a form of encryption, but it does provide a reliable way to ensure that your data remains intact during transmission. The decoding process will always restore the original binary data perfectly.
- Simplify the handling of binary data in text-based environments. By converting binary data to a simple string of characters, Base64 makes it easier to work with in programming languages and frameworks that are primarily designed to handle text.
- Achieve broad compatibility with a wide range of systems and protocols. The Base64 character set is designed to be universally recognized, ensuring that your encoded data can be correctly interpreted by almost any system, from modern web browsers to legacy email clients.
- Enhance security in certain applications by encoding credentials or other sensitive data. While not a substitute for proper encryption, Base64 can be used as part of a larger security strategy to obscure data and make it more difficult for casual observers to read.
When this is not the right tool
- The data must actually be protected rather than just carried as text. — file-encryptor for a file with a password, or a password manager for a secret, because Base64 hides nothing from anyone who receives it.
- The string is going into a URL and the goal is percent-encoding rather than Base64. — url-encoder, which escapes spaces, question marks, equals signs and non-ASCII characters, none of which Base64 or this tool addresses.
- Large or repeated conversions are needed, or the bytes come from a build step. — a command line tool such as base64 or openssl base64, which handle any size and can be scripted, where this tool takes one paste or one file at a time and stops at 25 MB.
Frequently asked questions
What is Base64?
Encoding converting binary to ASCII using 64 characters.
Why use it?
Safely transmit binary through text-only channels.
Is it encryption?
No, encoding only. Easily decoded by anyone.
Size increase?
About 33% larger than original.
Related tools in Developer Tools
- JSON Formatter — Free JSON Formatter and Validator — beautify, minify, validate, and debug JSON data instantly.
- URL Encoder/Decoder — URL Encoder/Decoder converts special characters to percent-encoded equivalents.
- HTML Entities Encoder/Decoder — Free HTML Entities Encoder and Decoder — convert special characters to safe HTML entities and back.
- Regex Tester — The Regex Tester lets you write, test, and debug regular expressions in real-time with match highlighting and capture group display.
- Timestamp Converter — The Timestamp Converter converts between Unix timestamps and human-readable dates.
- Color Contrast Checker — Free color contrast checker for web accessibility.
- File Encryptor — Encrypt a file with AES-256-GCM, using a key derived from your password with PBKDF2-SHA256.
Further reading
Base64 Encoder/Decoder: Encode and Decode Base64 Online
Encode text to Base64 or decode Base64 to text. Essential for developers working with APIs, data URIs, and encoded content.