Base64 Encoder & Decoder
Encode text or files to Base64 or a data URI, or decode Base64 back to text or a file.
Encodes text or a file, such as an image, to Base64 or a data URI, and decodes Base64 back to text or a file, including the URL-safe variant used in tokens and web addresses. Everything runs in your browser; nothing you paste or open is sent anywhere.
Options
- Mode — Encode or Decode. Switching carries the output into the input, so a round trip takes one click.
- Open file — when encoding, any file up to 50 MB, in place of text, with a thumbnail and pixel size for an image; when decoding, a text file holding Base64. Output past 1,000,000 characters is not all shown, but Copy and Download carry all of it.
- Output as — Base64, or a data URI to paste into HTML or CSS:
data:, the file's type, then its Base64. A data URI always uses the standard alphabet on one line, so URL-safe, padding and wrapping show only for Base64. For an image the browser shows, HTML gives an<img>tag with the image's size and CSS abackground-imagedeclaration, as Image to Base64 does. - Trim input — when encoding, ignores spaces and line breaks at the start and end; on by default.
- URL-safe Base64 — uses
-and_instead of+and/, so the result fits in URLs, file names and JSON Web Tokens. Turning it on also removes the padding, as JWTs do; padding can be turned back on. Decoding reads both alphabets without it. - Remove padding (=) — drops the trailing
=signs, as JWTs and many URLs do. Decoding accepts Base64 with or without padding. - Wrap lines — Off, or breaks the output into lines of 64 characters, as PEM keys and certificates use, or 76, the MIME email standard. Decoding ignores spaces and line breaks.
How it works
Text is converted to UTF-8 bytes, so accented letters, other scripts and emoji encode correctly. Every 3 bytes become 4 characters from a 64-character alphabet, which makes Base64 about a third longer than the original; = pads the end to a multiple of four.
Base64 is an encoding, not encryption: anyone can decode it. Decoded bytes that form valid UTF-8 are shown as text; anything else, such as an image, is shown in hex, and Download saves the file, named for its type where it is a common image or a PDF. A data URI, such as data:image/png;base64,…, decodes as its Base64, and its declared type names the file and shows an image as a preview.
A data URI's type comes from the file's first bytes for common images and PDF, then from the type the browser gives the file. Text that is valid UTF-8 gets ;charset=utf-8: RFC 2397, which defines data URIs, reads text without a charset as US-ASCII, which would garble accented letters. Base64 itself is defined in RFC 4648.
Examples
A small image as a data URI
- Image
- A 1 × 1 PNG, 70 bytes
- Data URI
- data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==
Paste it as <img src="data:…"> or in CSS as url(data:…): the image travels inside the page, saving a request, at a third more than its size. It suits icons and small images.
Decoding
- Base64
- Q29ybmVyVG9vbHM=
- Decoded
- CornerTools
Binary data
- Base64
- iVBORw0KGgo=
- Bytes
- 89 50 4e 47 0d 0a 1a 0a
These eight bytes open every PNG image. They are not valid UTF-8, so the tool shows them in hex and offers the file for download.
The variants side by side
| Variant | Result |
|---|---|
| Standard | SGk/IENhZsOpIOKYlQ== |
| URL-safe | SGk_IENhZsOpIOKYlQ== |
| URL-safe, no padding | SGk_IENhZsOpIOKYlQ |
See also
- JWT Decoder & Encoder — to read the Base64URL-encoded parts of a token.
- URL Encoder & Decoder — for percent-encoding text in URLs.
- Image to Base64 — for an image as a data URI, an HTML <img> tag or a CSS background, with a preview.