Base64 Encoder/Decoder

Advertisement

Enter text or upload a file to encode to Base64, or paste Base64 to decode.

Input
Drop file here or click to browse
Output

How to Use

  1. Choose Text or File mode, then enter text to encode or paste Base64 to decode.
  2. Select Encode or Decode, and optionally enable URL-safe mode or Data URI prefix for images.
  3. Copy the encoded/decoded result or download the output. Share via link to preserve your input.
Advertisement

About This Tool

Base64 is a binary-to-text encoding scheme that represents binary data using a set of 64 printable ASCII characters. The character set includes uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and two additional symbols (+ and /), with the equals sign (=) used as a padding character. This encoding method was designed to ensure that binary data can be safely transmitted through text-only communication channels without corruption or data loss. The Base64 encoding standard is formally defined in RFC 4648 (published in 2006), which superseded the earlier RFC 3548. However, Base64's roots go much deeper, originating from the MIME (Multipurpose Internet Mail Extensions) standard published in 1996. MIME needed a reliable way to attach binary files like images, documents, and executables to email messages, which were originally designed to carry only 7-bit ASCII text. Base64 became the solution that made modern email attachments possible. Base64 encoding is essential whenever binary data must pass through systems that only support text. Email remains one of the most common use cases, but web development has expanded Base64's role significantly. Data URIs allow developers to embed images, fonts, and other resources directly in HTML and CSS using Base64 strings, eliminating extra HTTP requests and improving page load performance for small assets. In API development, HTTP Basic Authentication encodes credentials using Base64, and JSON Web Tokens (JWT) use Base64url encoding for their header and payload segments. This tool implements both standard Base64 and the URL-safe variant defined in RFC 4648 Section 5, which replaces + with - and / with _ to avoid conflicts with URL special characters. All encoding and decoding operations run entirely in your browser using JavaScript, ensuring your data never leaves your device.

Sources: IETF

The Science and History of Base64 Encoding

The mathematical foundation of Base64 lies in radix conversion—the same principle used when converting between decimal, binary, and hexadecimal number systems. Base64 uses a radix of 64, meaning each character position can represent one of 64 distinct values. Since 64 equals 2 to the power of 6, each Base64 character encodes exactly 6 bits of information, creating an elegant alignment between binary data and printable characters. The choice of 64 as the radix was deliberate. It is the largest power of two that produces characters entirely within the printable ASCII range (codes 32-126), maximizing information density while remaining compatible with text-based systems. Earlier schemes experimented with Base16 (hexadecimal, using 4 bits per character) and Base32 (5 bits per character), but these were less efficient. Base64 achieves a near-optimal balance, encoding 6 of every 8 bits per character for a 75% efficiency ratio. The history of Base64 traces back to the Privacy Enhanced Mail (PEM) standard in 1987, which first specified a 64-character encoding for email. The MIME standard adopted and refined this in 1996, establishing the character alphabet still used today. RFC 2045 codified the MIME version, while RFC 4648 (published in 2006) consolidated Base64 along with Base32 and Base16 into a single reference document, adding the URL-safe alphabet variant. Modern applications have extended Base64 far beyond its email origins. JSON Web Tokens use Base64url encoding to represent claims in a compact, URL-safe format. Source maps in JavaScript minification encode file mappings using a variable-length Base64 scheme called VLQ (Variable-Length Quantity). Even the git version control system uses Base64 internally when transmitting binary patches over text-based protocols. The encoding remains one of the most widely deployed data transformation schemes in computing history.

How to Use

  1. Choose Text or File mode, then enter text to encode or paste Base64 to decode.
  2. Select Encode or Decode, and optionally enable URL-safe mode or Data URI prefix for images.
  3. Copy the encoded/decoded result or download the output. Share via link to preserve your input.

Methodology

Base64 encoding converts binary data to a 64-character ASCII subset (A-Z, a-z, 0-9, +, /). The algorithm processes input in blocks of three bytes (24 bits), splitting each block into four 6-bit groups. Each 6-bit group maps to one of the 64 characters in the encoding alphabet, producing four output characters for every three input bytes. This results in an output size approximately 33% larger than the input. When the input length is not a multiple of three bytes, padding characters (=) are appended to maintain proper four-character alignment. This tool uses JavaScript's built-in btoa() function for encoding and atob() for decoding text data. For non-ASCII characters such as accented letters, emoji, or CJK ideographs, the text is first converted to a UTF-8 byte sequence using TextEncoder before Base64 encoding. File encoding leverages the FileReader API to read binary data directly as an ArrayBuffer, then converts the byte array to a Base64 string character by character. The URL-safe variant substitutes + with - and / with _ as specified in RFC 4648 Section 5, making the output safe for use in URLs and filenames without additional escaping.

Sources: IETF

Understanding Your Results

Use Base64 to embed images in CSS/HTML via Data URIs with the format 'data:mime/type;base64,...'. This eliminates extra HTTP requests for small assets like icons and logos, improving initial page load performance. For JSON APIs, Base64 lets you transmit binary payloads such as thumbnails, signatures, or document attachments within text-based JSON structures. The encoded output is always approximately 33% larger than the original input because three bytes of data expand to four Base64 characters. Keep this overhead in mind when embedding large files, as the size increase can outweigh the benefit of fewer HTTP requests. For images larger than a few kilobytes, serving them as separate files is usually more efficient. Invalid Base64 input—containing characters outside the allowed alphabet or incorrect padding—will produce a decoding error. If you encounter errors, check for accidental whitespace, line breaks, or copy-paste artifacts. Remember that Base64 is an encoding scheme, not encryption. Anyone can decode a Base64 string instantly, so never use it to protect sensitive information like passwords, API keys, or personal data.

Practical Examples

Embedding a small logo in CSS: encode a PNG file with the Data URI option enabled, then use the result as background-image: url('data:image/png;base64,...') to eliminate an HTTP request. API authentication headers: encode 'username:password' to Base64 for HTTP Basic Auth, producing the Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ= header. Storing binary data in JSON: encode a PDF or image attachment to Base64, then include it as a string field in your JSON payload for transmission through text-only APIs. Email systems: MIME encoding attaches binary files to email messages by converting them to Base64, which is why forwarded attachments sometimes appear as long Base64 strings. JWT token inspection: split a JWT on its two dots, then decode the first two segments (header and payload) from Base64url to read the token claims without needing a dedicated JWT library.

Tips & Best Practices

Use the URL-safe variant whenever your Base64 output will appear in URLs, query parameters, or filenames. Standard Base64 characters + and / conflict with URL delimiters and can cause silent data corruption if not handled properly. For web development, enable the Data URI prefix when encoding images smaller than 5-10 KB. This inlines the image directly into your HTML or CSS, saving an HTTP round-trip. For larger images, the 33% size overhead of Base64 makes separate file serving more efficient. When decoding fails, check for trailing whitespace, line breaks, or missing padding characters. Many systems strip or add whitespace when copying Base64 strings. If you pasted from an email or document, invisible characters may have been introduced. For API debugging, decode JWT tokens by splitting on dots and decoding each segment separately. The header and payload segments use Base64url encoding, so enable the URL-safe option first.

All calculations are performed locally in your browser. No data is sent to any server.

Embed This Tool

Get embed code

Was this tool helpful?
Want to tell us more?
0/500
Want us to follow up?
Thanks for your feedback!

Frequently Asked Questions

What is Base64 encoding used for?
Base64 converts binary data into ASCII text, making it safe to transmit through systems that only handle text. Common uses include embedding images in HTML/CSS, sending attachments in emails, storing binary data in JSON, and passing data in URLs. It's essential for APIs and web development.
What is URL-safe Base64?
Standard Base64 uses + and / characters which have special meaning in URLs and can cause problems. URL-safe Base64 replaces + with - and / with _ to avoid these issues. Use this option when the encoded data will be passed in URLs or query parameters.
Can I encode files like images?
Yes! Switch to File mode and upload any file to convert it to Base64. For images, you can enable the Data URI option to get a complete data:image/... string that can be used directly in HTML img tags or CSS background properties. This is useful for embedding small images without separate HTTP requests.
Is there a size limit for encoding?
Since all processing happens in your browser, the limit depends on your device's available memory. Text encoding works well for megabytes of data. For files, browsers can typically handle files up to 50-100MB, though very large files may slow down your browser. Base64 output is about 33% larger than the original data.
Is my data private when using this tool?
Yes, completely. All Base64 encoding and decoding runs entirely in your browser using JavaScript. Your data is never sent to any server or third party. This makes the tool safe for encoding sensitive information such as API keys, authentication tokens, or confidential documents.
Is Base64 encoding the same as encryption?
No, Base64 is an encoding scheme, not encryption. It transforms data into a different representation but provides no security — anyone can decode it instantly. Base64 is designed for safe data transport, not confidentiality. If you need to protect sensitive data, use proper encryption algorithms like AES before optionally Base64-encoding the encrypted output.