Encoding & Decoding

Base64 Encode: How to Encode Text and Files to Base64 Online

Learn how Base64 encoding works, when to use it, and how to encode text or binary data to Base64 strings quickly in your browser.

Published January 15, 2025Updated June 1, 20255 min read

Try the free online tool

Runs entirely in your browser — no signup, no uploads.

Open Tool

Base64 encoding is one of the most widely used data-encoding schemes in software development. It converts arbitrary binary data into a safe, ASCII-printable string using only 64 characters: A-Z, a-z, 0-9, +, and /. Because the output contains no whitespace, null bytes, or control characters, Base64-encoded data travels safely through systems that were designed to handle only text.

You encounter Base64 every day without knowing it. Email attachments are Base64-encoded by the MIME standard. Inline images embedded in CSS or HTML use Base64 data URIs. JSON payloads that carry binary blobs rely on Base64 to avoid encoding conflicts. Even browser cookies and JWTs use Base64 URL variants to carry structured data.

This tool lets you encode any text or binary string to Base64 directly in your browser without sending data to a server. Paste your input, click encode, and copy the result. It is fast, private, and requires no installation.

What Is Base64 Encoding?

Base64 is a binary-to-text encoding scheme standardised in RFC 4648. It works by grouping the input bytes into chunks of three (24 bits) and then splitting each chunk into four 6-bit values. Each 6-bit value maps to one of 64 printable ASCII characters. If the input length is not a multiple of three, padding characters (=) are appended to complete the final group.

The name comes from the 64-character alphabet used. Standard Base64 uses + and / as the 62nd and 63rd characters, which can cause problems in URLs and filenames. The URL-safe variant (Base64url, defined in RFC 4648 Section 5) replaces + with - and / with _ to avoid percent-encoding issues in query strings.

The encoding increases size by roughly 33 percent because every 3 bytes of input become 4 bytes of output. This overhead is acceptable in most use cases because the portability and compatibility benefits far outweigh the cost.

How to Use This Tool

Encoding text or binary data with this tool takes only a few seconds.

  1. 1

    Paste or type your input

    Enter the plain text, JSON, XML, or any string you want to encode into the input field.

  2. 2

    Choose the variant

    Select Standard Base64 (RFC 4648) or URL-safe Base64url depending on where the output will be used.

  3. 3

    Click Encode

    The tool converts your input instantly and displays the Base64 output in the result field.

  4. 4

    Copy the result

    Use the Copy button to copy the encoded string to your clipboard, ready to paste into code, headers, or config files.

  5. 5

    Optionally download

    For large outputs, use the Download button to save the encoded string as a .txt file.

Common Use Cases

Base64 encoding is used across virtually every layer of the modern software stack.

  • Embedding images or fonts directly in CSS using data URIs to eliminate extra HTTP requests.
  • Encoding binary file attachments (PDFs, images) in MIME email messages.
  • Passing binary blobs inside JSON payloads where null bytes would break parsers.
  • Storing small binary assets in environment variables or configuration files.
  • Encoding the header and payload portions of JSON Web Tokens (JWTs).
  • Transmitting cryptographic keys and certificates in PEM format.

Tips and Best Practices

  • Use URL-safe Base64 (Base64url) whenever the output will appear in a URL query string or path segment to avoid double percent-encoding.
  • Remember that Base64 is encoding, not encryption. Never use it to protect sensitive data; use proper encryption algorithms instead.
  • When embedding Base64 images in CSS, keep files small (under 10 KB) to avoid bloating your stylesheet and hurting parse performance.
  • Strip padding characters (=) when storing Base64 in databases or URL parameters; add them back before decoding to avoid errors.
  • Validate your input encoding before Base64-encoding: ensure the source string is UTF-8 if you intend to decode it back to text later.

Base64 in HTTP and API Development

HTTP Basic Authentication encodes credentials as Base64 in the Authorization header: the string username:password is Base64-encoded and sent as Authorization: Basic <encoded>. While this is not secure without HTTPS, understanding it helps when debugging auth issues with curl or Postman.

REST and GraphQL APIs frequently accept or return Base64-encoded binary fields. When an image upload endpoint accepts a JSON body, it typically expects the file content as a Base64 string under a key like imageData. Knowing how to quickly encode a file for testing speeds up API development significantly.

Frequently Asked Questions

Is Base64 the same as encryption?

No. Base64 is a reversible encoding scheme with no secret key. Anyone who has the Base64 string can decode it instantly. It provides no confidentiality. Use AES or RSA for actual encryption.

Why does Base64 output end with one or two equals signs?

The = characters are padding. Base64 processes input in groups of 3 bytes (24 bits). If the final group has only 1 or 2 bytes, padding is added so the total length is a multiple of 4 characters. One remaining byte gives == and two remaining bytes give =.

What is the difference between standard Base64 and Base64url?

Standard Base64 uses + and / as characters 62 and 63. These characters have special meaning in URLs. Base64url replaces + with - and / with _ so the output can be used safely in URL path segments and query parameters without percent-encoding.

How much larger is Base64 output compared to the original input?

Base64 output is approximately 33 percent larger than the input because every 3 bytes of input become 4 characters of output. For example, a 300-byte input produces roughly 400 characters of Base64.

Can I Base64-encode binary files like images with this tool?

This tool encodes text input. To encode binary files, you would need to read the file as binary and then encode it. Browser-based tools can accept file uploads and use the FileReader API to convert the binary content to Base64 before display.

Does Base64 encoding preserve Unicode characters?

Yes, but you must ensure the text is first converted to UTF-8 bytes before encoding. JavaScript's btoa() function only accepts Latin-1 characters; to encode Unicode text, convert it to UTF-8 bytes first and then apply Base64 encoding.

Where is Base64 used in JWTs?

JWTs consist of three Base64url-encoded parts separated by dots: the header, the payload, and the signature. The header and payload are Base64url-encoded JSON objects. Note that the encoding is Base64url without padding, not standard Base64.

base64encodingbinarydata-uriascii

Ready to use this tool?

Free, instant, no account required. Runs entirely in your browser.

Open Tool

More Encoding & Decoding Guides