Skip to content

Base64 Encoder

Type text or open a file to encode it as Base64. Text is read as UTF-8, so emoji and accented characters encode correctly.

Text
Base64

    
Ready

Last reviewed:

What is Base64?

Base64 is a way to write arbitrary bytes using only 64 printable ASCII characters: A-Z, a-z, 0-9, + and /, with = used as padding. It exists because many channels developers rely on only carry text safely: JSON strings, HTTP headers, email bodies, XML, environment variables and URLs. Base64 lets an image, a certificate or an encryption key travel through those channels unchanged.

The algorithm reads the input three bytes (24 bits) at a time and splits them into four 6-bit groups. Each group is a number from 0 to 63, which picks one character from the alphabet. When the input length is not a multiple of three, the last group is padded and one or two = signs are added. As a result, Base64 output is always about 33% larger than the input.

Base64 encodes bytes, not characters. Text has to be turned into bytes first, and this tool always uses UTF-8, which is what nearly every modern system expects. RFC 4648 also defines Base64URL, a variant that uses - and _ instead of + and / so the result is safe in URLs and filenames. JWTs and many OAuth parameters use it, usually without padding.

How to use this tool

  1. Type or paste text into the Text box (or click Paste). The Base64 output updates as you type.
  2. To encode a file instead, click Open file… and choose it. The text box shows the file name and size; click Clear to go back to typing text.
  3. Tick URL-safe (Base64URL) to swap + and / for - and _ and remove the = padding.
  4. Tick Wrap lines at 76 to break the output into 76-character lines, as MIME email and PEM files expect.
  5. Tick Output as data URI to get a complete data: URL with the file's MIME type (or text/plain;charset=utf-8 for text), ready for an src or CSS url().
  6. Click Copy or Download. For very large files the on-screen preview is truncated, but Copy and Download always contain the full result.

Examples

Text, including non-ASCII characters

Input UTF-8 bytes Base64
Hi! 3 SGkh
Hi 2 SGk=
H 1 SA==
café ☕ 9 Y2Fmw6kg4piV

The last row is six characters long but nine bytes in UTF-8, because é takes two bytes and ☕ takes three.

Standard versus URL-safe output

Input:      subjects?_d>>
Standard:   c3ViamVjdHM/X2Q+Pg==
URL-safe:   c3ViamVjdHM_X2Q-Pg

The standard form contains /, + and =, which have special meanings in URLs. The URL-safe form replaces them and drops the padding.

A Basic authentication header

Input:   api-user:s3cr3t!
Base64:  YXBpLXVzZXI6czNjcjN0IQ==
Header:  Authorization: Basic YXBpLXVzZXI6czNjcjN0IQ==

Anyone who sees this header can decode the password, which is why Basic authentication must only be used over HTTPS.

A small SVG as a data URI

With Open file… on an 8×8 SVG of a red circle and Output as data URI ticked:

data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4IiBoZWlnaHQ9IjgiPjxjaXJjbGUgY3g9IjQiIGN5PSI0IiByPSI0IiBmaWxsPSJyZWQiLz48L3N2Zz4=

Common errors and how to fix them

  • The other side cannot decode it. Check that both sides use the same alphabet. A standard decoder rejects - and _, and some URL-safe decoders reject +, / or =. Tick or untick URL-safe to match.
  • Missing padding. Some libraries require the = padding that Base64URL usually omits. Add = until the length is a multiple of four, or use a decoder with a "no padding" option.
  • Accented characters come out garbled after decoding. The receiver is decoding the bytes as Latin-1 or Windows-1252 instead of UTF-8. For example, é is w6k= in UTF-8 but 6Q== in Latin-1.
  • btoa() throws "Invalid character" in your own code. The browser's btoa only accepts characters up to U+00FF. Encode the string to UTF-8 bytes first with TextEncoder, which is what this tool does.
  • Line breaks break the value. Wrapped Base64 (76 characters per line) is required for MIME but breaks JSON fields, HTTP headers and many decoders. Leave wrapping off unless the format asks for it.
  • A trailing newline changed the result. Encoding hello and hello followed by Enter gives different output. Make sure you encode exactly the bytes you mean to.

When developers use this

  • Putting a small binary value, such as a thumbnail, a public key or a signature, into a JSON field or an environment variable.
  • Building Authorization: Basic header values for testing an API.
  • Inlining a tiny icon or font as a data URI to save an HTTP request.
  • Preparing values for a Kubernetes Secret manifest, whose data fields must be Base64.
  • Embedding a certificate or key in CI configuration where only single-line text is allowed.
  • Checking what an encoded value in a log or URL should look like for a given input.

Privacy and how it works

Encoding runs entirely in your browser: text is converted to UTF-8 with TextEncoder, files are read with the File API, and the result is produced with btoa. Nothing is uploaded. Values you encode are often credentials or keys, and a Base64 string offers no protection at all, so keeping both the input and the output off third-party servers is the sensible default.

Limitations

  • Base64 is not encryption. Anyone can decode it instantly. Do not use it to hide passwords, API keys or personal data; encrypt or hash them instead.
  • This tool encodes only. To decode, paste the value into a JWT decoder for tokens, or use atob or base64 -d for other data.
  • Very large files (hundreds of megabytes) are limited by browser memory, and Base64 output is a third larger than the file itself.

FAQ

Is Base64 a form of encryption?

No. It is a reversible change of format with no key, so it hides nothing. Kubernetes Secrets and Basic auth headers are Base64-encoded only to make bytes safe to transport, not to protect them.

Why is the output bigger than the input?

Every 3 bytes become 4 characters, so the output is roughly 4/3 of the input size, plus up to two padding characters. Wrapping lines adds a newline every 76 characters on top of that.

When should I use URL-safe Base64?

Whenever the value goes into a URL, a cookie, a filename or a JWT. The standard characters +, / and = are meaningful in URLs and would have to be percent-encoded; Base64URL avoids them.

What does the = at the end mean?

It is padding. One = means the last group contained two bytes, == means it contained one. It tells strict decoders where the data ends; many modern decoders can work without it.

Why do I get different output from another tool for the same text?

Usually because of the text encoding or invisible characters. This tool encodes UTF-8; tools or languages that use UTF-16 or Latin-1 produce different bytes. A trailing newline or a Windows line ending also changes the result.

Should I use data URIs for images on my site?

Only for very small assets, such as icons under a few kilobytes. A data URI is a third larger than the file, cannot be cached separately and delays rendering of the page that contains it. Larger images are better served as normal files.

Are my files uploaded?

No. Files are read and encoded in your browser and never leave your device. You can disconnect from the network after the page has loaded and the tool keeps working.

Guides