Base64 Encode / Decode
Encode text as Base64, or decode Base64 back to the original text. Besides UTF-8, UTF-16 (PowerShell) and charsets for Western European languages, Japanese (including ISO-2022-JP for email), Korean, Chinese, and Thai are supported, and the charset is detected automatically when decoding.
Conversion happens entirely in your browser. Nothing you enter is sent to a server.
Examples:
What is Base64?
Base64 represents data using only 64 characters: letters, digits, + and / (RFC 4648). It is used to exchange data where only text is allowed, such as email attachments and bodies, data URIs that embed images in HTML or CSS, Basic authentication, and JWTs.
The data is split into groups of 3 bytes (24 bits), and each group is turned into 4 characters of 6 bits each. As a result, Base64 is about 4/3 the size of the original (about 33% larger). For example, “café” is 63 61 66 C3 A9 (5 bytes) in UTF-8, so it becomes the 8 characters Y2Fmw6k=.
Base64 is not encryption. Anyone can decode it, so it cannot be used to hide passwords or other secrets.
Standard vs. URL-safe Base64
The last 2 of the 64 characters differ between the alphabets. The standard + and / have special meanings in URLs, so use URL-safe Base64 (Base64URL) in URLs and file names. When decoding, both alphabets are accepted.
| Alphabet | Characters 62 and 63 | Typical uses |
|---|---|---|
| Standard (+ /) | + / | Email (MIME), data URIs, Basic authentication, the standard functions of most languages |
| URL-safe (- _) | - _ | URL queries and paths, file names, JWTs (without padding) |
Padding (=) and line wrapping
Base64 works in groups of 4 characters. When the data length is not a multiple of 3 bytes, the end is padded with = to make a full group: == for 1 leftover byte and = for 2. URL-safe Base64, such as in JWTs, often omits the padding. When decoding, padding is optional.
Email (MIME) wraps lines at 76 characters, and the PEM format used for certificates wraps at 64. When decoding, line breaks and spaces are ignored. If each line is a separate Base64 string, choose “Convert each line separately”. When “Convert each line separately” is selected, lines are not wrapped.
Differences between charsets
Base64 encodes bytes, not characters, so the result depends on the charset used to turn the text into bytes. Encoding “café” gives the following. Japanese email uses ISO-2022-JP, and PowerShell’s -EncodedCommand uses UTF-16LE.
| Charset | Encoded result |
|---|---|
| UTF-8 | Y2Fmw6k= |
| UTF-16LE | YwBhAGYA6QA= |
| UTF-16BE | AGMAYQBmAOk= |
| Shift_JIS (CP932) | Not available in this charset |
| EUC-JP | Not available in this charset |
| ISO-2022-JP | Not available in this charset |
| EUC-KR (CP949) | Not available in this charset |
| GBK | Y2FmqKY= |
| Big5 | Not available in this charset |
| Windows-874 (TIS-620) | Not available in this charset |
| Windows-1252 (ISO-8859-1) | Y2Fm6Q== |
Functions in programming languages
Common functions and the settings in this tool that give the same result (for UTF-8 text). Functions that wrap lines differ in their line endings (LF or CRLF) and in whether they add a final line break. JavaScript’s btoa() only handles Latin-1 characters, so other text must first be converted to UTF-8 bytes.
| Language | Function | Alphabet | Padding | Line wrapping |
|---|---|---|---|---|
| JavaScript | btoa() | Standard (+ /) | Yes | No wrapping |
| JavaScript | Uint8Array.prototype.toBase64() | Standard (+ /) | Yes | No wrapping |
| JavaScript | toBase64({ alphabet: 'base64url' }) | URL-safe (- _) | Yes | No wrapping |
| Node.js | buffer.toString('base64') | Standard (+ /) | Yes | No wrapping |
| Node.js | buffer.toString('base64url') | URL-safe (- _) | No | No wrapping |
| PHP | base64_encode() | Standard (+ /) | Yes | No wrapping |
| PHP | chunk_split(base64_encode()) | Standard (+ /) | Yes | 76 characters (MIME) |
| Python | base64.b64encode() | Standard (+ /) | Yes | No wrapping |
| Python | base64.urlsafe_b64encode() | URL-safe (- _) | Yes | No wrapping |
| Python | base64.encodebytes() | Standard (+ /) | Yes | 76 characters (MIME) |
| Java | Base64.getEncoder() | Standard (+ /) | Yes | No wrapping |
| Java | Base64.getUrlEncoder().withoutPadding() | URL-safe (- _) | No | No wrapping |
| Java | Base64.getMimeEncoder() | Standard (+ /) | Yes | 76 characters (MIME) |
| Go | base64.StdEncoding | Standard (+ /) | Yes | No wrapping |
| Go | base64.RawURLEncoding | URL-safe (- _) | No | No wrapping |
| Ruby | Base64.strict_encode64() | Standard (+ /) | Yes | No wrapping |
| Ruby | Base64.urlsafe_encode64() | URL-safe (- _) | Yes | No wrapping |
| C# | Convert.ToBase64String() | Standard (+ /) | Yes | No wrapping |
How to use
- Choose “Encode” or “Decode”.
- Choose a charset. When decoding, “Auto-detect” tries UTF-8 first and then gives priority to the charsets commonly used for the language of this page (Windows-1252 on English pages). ISO-2022-JP and UTF-16 are detected when their telltale signs are present.
- When encoding, choose the alphabet, padding, and line wrapping. To convert each line separately, choose “Convert each line separately”.
- Type text in the input box and the result appears immediately. Use “Copy” to copy the result.
FAQ
Is what I enter sent to a server?
No. All conversion happens in your browser, and nothing you enter is stored.
Is Base64 encryption?
No. Base64 is a way of representing data as text, and anyone can decode it. Use encryption to protect passwords or personal information.
What is the = at the end?
It is padding. Base64 works in groups of 4 characters, and = fills the last group when the data length is not a multiple of 3 bytes. Removing it does not change the data, so this tool can decode Base64 without padding.
The decoded text is garbled.
The text may have been encoded in a different charset than the one you are decoding with. Try “Auto-detect”, or choose the charset used for encoding (for example, Windows-1252, Shift_JIS, ISO-2022-JP, EUC-KR, GBK, or Big5).
It says the data may not be text.
The decoded result contains control characters that are not used in text. The Base64 may be an image, a file, or other non-text data. This tool only converts text.
Can I decode an email subject such as =?ISO-2022-JP?B?...?=?
The part between ?B? and ?= is Base64. Enter that part and choose “Auto-detect” or ISO-2022-JP as the charset. For =?UTF-8?B?...?=, choose UTF-8.
Half-width katakana becomes full-width when encoding with ISO-2022-JP.
ISO-2022-JP has no half-width katakana, so they are converted to full-width katakana (voiced sound marks become ゛ and ゜), as browsers and email clients do. To keep half-width katakana, choose Shift_JIS or UTF-8.
Can I create a string for PowerShell’s -EncodedCommand?
Yes. -EncodedCommand expects Base64 of UTF-16LE text, so choose UTF-16LE as the charset when encoding. UTF-8 will not work.
Auto-detect picks a different charset from the one used for encoding.
The same bytes can often be read in several charsets. Auto-detect tries UTF-8 first and then gives priority to the charsets commonly used for the language of the page, so the same input may give a different result depending on the page language. The detected charset is shown below the result; if it is wrong, choose the charset yourself.