Base64 encode text and files
Base64 is a way to write arbitrary bytes using only 64 safe, printable ASCII characters. You Base64 encode data when it has to pass through a channel built for text: JSON and XML documents, email bodies, HTTP headers, URLs, environment variables, or configuration files. This encoder converts text (as UTF-8) or an uploaded file into Base64 instantly, in your browser.
How Base64 works
- The input is read as bytes. Text is converted to UTF-8 first, so “é” is two bytes and an emoji four.
- Bytes are taken three at a time — 24 bits — and split into four 6-bit groups.
- Each 6-bit value (0–63) picks a character from the alphabet
A–Z a–z 0–9 + /. - If the last group has only one or two bytes, the output is padded with
==or=so its length is a multiple of four.
Because every 3 bytes become 4 characters, Base64 output is about 33% larger than the input. Base64 is an encoding, not encryption: anyone can decode it, so it offers no confidentiality.
Examples
| Input | Base64 | Notes |
|---|---|---|
Man | TWFu | 3 bytes → 4 characters, no padding |
Ma | TWE= | 2 bytes → one = pad |
M | TQ== | 1 byte → two = pads |
Hello, World! | SGVsbG8sIFdvcmxkIQ== | 13 bytes |
héllo ✓ | aMOpbGxvIOKckw== | UTF-8 multi-byte characters |
Options explained
Standard vs. URL-safe alphabet
The standard alphabet (RFC 4648 §4) uses + and /, which have special meanings in URLs and file names. The URL-safe variant, often called Base64URL (RFC 4648 §5), replaces them with - and _ and drops the = padding. It is used by JSON Web Tokens, many OAuth and WebAuthn values and signed URLs. For example, ?>? encodes to Pz4/ in standard Base64 and Pz4_ in the URL-safe form.
MIME line wrapping
Email (MIME, RFC 2045) limits encoded lines to 76 characters. Tick Wrap lines at 76 chars to insert line breaks, which is what you need for hand-built email bodies and some legacy systems. Leave it off for JSON, HTTP headers and data URIs, where line breaks would break the value. PEM certificate files use a similar layout with 64-character lines.
Encoding files
Use Open file on the Text box, or drop a file on it, to encode binary files such as PDFs, certificates or archives; the bytes are read directly, so nothing is altered by text conversion. For images you want to embed in HTML or CSS, the Image to Base64 tool produces a complete data URI with the right MIME type.
Why btoa() fails and this does not
In JavaScript, btoa("✓") throws “InvalidCharacterError” because btoa only accepts characters up to U+00FF. The fix is to encode to UTF-8 bytes first — btoa(String.fromCharCode(...new TextEncoder().encode(s))) or Buffer.from(s).toString('base64') in Node.js — which is exactly what this tool does. In Python, use base64.b64encode(s.encode('utf-8')); on the command line, printf '%s' 'text' | base64 (note that echo adds a trailing newline, which changes the result).
Common uses
- HTTP Basic authentication headers, which carry
username:passwordin Base64. Because Base64 is not encryption, Basic auth must only be used over HTTPS. - Embedding binary data — keys, certificates, small images — in JSON, YAML or XML.
- Kubernetes Secret values, which are stored Base64 encoded (again, encoding rather than protection).
- Email attachments and inline images in MIME messages.
Decode Base64 back with the Base64 Decoder. Encoding runs entirely in your browser; the text and files you use are not uploaded unless you click Save & Share, which stores the text shown in the input box.