How to encode text to Base64
- Type or paste your text into the Input · text box. The page opens with a sample; press Clear to start empty.
- The Base64 appears in Output · Base64 while you type. For very large inputs you can untick Live and press Run instead.
- Set the options the receiving system expects: URL-safe (- _), No padding (=), Line wrap and Charset. The defaults (standard alphabet, padded, one line, UTF-8) suit most APIs.
- Press Copy output, or Download to save the result as
base64.txt. - To check the round trip, press Swap. It moves the Base64 into the input and switches the tool to decoding.
Under the buttons you see the input size in bytes, the output size and the percentage change, which is handy when a field has a length limit.
How Base64 encoding works
Base64 works on bytes, so the first step is turning your text into bytes with a charset (UTF-8 here unless you pick another). The encoder then takes the bytes three at a time, which is 24 bits, splits them into four 6-bit numbers and writes each number as one character from a 64-character alphabet: A–Z, a–z, 0–9, + and /.
The text Man is the classic example: the bytes 4D 61 6E become TWFu. When the last group has only one or two bytes, the output is completed with =: Ma becomes TWE= and M becomes TQ==. The full walk-through is in how Base64 works, and padding explained covers when the = can be dropped.
The output length is always 4 × ⌈n / 3⌉ characters for n bytes, about 33% more than the input. The Base64 size calculator does that sum for any size, and Base64 size overhead explains when it matters. Base64 is reversible by anyone, so it hides nothing; read encoding vs encryption before putting secrets in it.
Encoding options
| Option | What it changes | When to use it |
|---|---|---|
| URL-safe (- _) | + becomes - and / becomes _ (RFC 4648 section 5) | URLs, query strings, file names, cookies, JWT. The Base64URL encoder has it on by default |
| No padding (=) | Drops the trailing = characters | JWT and most URL-safe formats; anything that strips = anyway |
| Line wrap: 76 (MIME, LF or CRLF) | Inserts a line break every 76 characters | Email bodies and attachments (MIME encoder) |
| Line wrap: 64 (PEM) | Inserts a line break every 64 characters | Certificates and keys between -----BEGIN and -----END lines |
| Charset | Which bytes each character becomes before encoding | UTF-8 unless the receiver expects UTF-16, Windows-1251, Shift_JIS or another legacy encoding |
Examples with Unicode, emoji and URL-safe output
Every value below was produced with Python’s base64 module and matches what this tool outputs.
| Input | Settings | Base64 |
|---|---|---|
Hello | UTF-8 | SGVsbG8= |
Hello, world! | UTF-8 | SGVsbG8sIHdvcmxkIQ== |
café | UTF-8 | Y2Fmw6k= |
café | ISO-8859-1 | Y2Fm6Q== |
€ | UTF-8 | 4oKs |
€ | Windows-1252 | gA== |
👋 | UTF-8 | 8J+Riw== |
👋 | UTF-8, URL-safe, no padding | 8J-Riw |
Привет | UTF-8 | 0J/RgNC40LLQtdGC |
Привет | Windows-1251 | z/Do4uXy |
The same word gives different Base64 in different charsets because the bytes differ: é is two bytes (C3 A9) in UTF-8 and one byte (E9) in Latin-1. The waving-hand emoji is four UTF-8 bytes, so on its own it takes 8 characters, two of them padding.
Charsets and characters that do not fit
UTF-8 can represent every Unicode character, so it never loses anything. The other 26 charsets in the list (UTF-16LE/BE, UTF-32LE, ASCII, the ISO-8859 and Windows code pages, KOI8-R/U, CP866, Shift_JIS, EUC-JP, GBK, Big5 and EUC-KR) exist for systems that expect them. If your text contains a character the chosen charset lacks, it is replaced with ? and a warning says how many characters were replaced. € in ISO-8859-1, for example, encodes as Pw==, which is just a question mark.
Pick UTF-16LE for Windows and .NET strings and for PowerShell; the UTF-16 to Base64 page explains why. Pick ASCII when a system must reject anything outside 7-bit text (ASCII to Base64).
Line wrapping
Plain Base64 is one long line, which is what JSON, HTTP headers, URLs and environment variables need. Email uses 76-character lines (RFC 2045) and PEM files use 64. The wrap option inserts \n line breaks at that width, or CRLF with 76 (MIME, CRLF). Decoders, including this site’s decoder, skip the line breaks, so wrapped output decodes to the same bytes. Base64 in email covers the MIME rules.
Common encoding mistakes
- A trailing newline sneaks in.
echo Hello | base64printsSGVsbG8Kbecauseechoadds\n. The textHelloalone isSGVsbG8=. Useprintf '%s', and when pasting here, check that the input byte count is what you expect. btoa()throws on Unicode. In browsers,btoa("Grüße 👋")raisesInvalidCharacterError, becausebtoaaccepts only Latin-1 characters. Encode to UTF-8 bytes first, as in the snippet below.- The receiver uses another charset. If you encode UTF-8 and the other side decodes as Latin-1,
cafécomes out ascafé. Agree on the charset, or pick the receiver’s charset here. - Encoding twice. Base64 of
SGVsbG8=isU0dWc2JHOD0=. If a value decodes to more Base64, something in the pipeline encoded it a second time. +and/break URLs. In a query string+is read as a space. Use the URL-safe option or the Base64URL encoder, or percent-encode the value.
Base64 encode in JavaScript, Python and the command line
In browser JavaScript, convert the string to UTF-8 bytes with TextEncoder, then encode the bytes. Newer browsers can call bytes.toBase64() directly (Uint8Array.toBase64).
const bytes = new TextEncoder().encode("Grüße 👋");
let bin = "";
for (const b of bytes) bin += String.fromCharCode(b);
btoa(bin); // "R3LDvMOfZSDwn5GL"
// Node.js
Buffer.from("Grüße 👋", "utf8").toString("base64"); // "R3LDvMOfZSDwn5GL"
Buffer.from("👋", "utf8").toString("base64url"); // "8J-Riw"
In Python, b64encode takes bytes and returns bytes:
import base64
base64.b64encode("Grüße 👋".encode("utf-8")).decode("ascii")
# 'R3LDvMOfZSDwn5GL'
base64.urlsafe_b64encode("👋".encode()).rstrip(b"=").decode()
# '8J-Riw'
On Linux and macOS, the base64 command encodes standard input:
printf '%s' 'Grüße 👋' | base64
base64 -w 0 file.bin > file.b64
The first command prints R3LDvMOfZSDwn5GL. GNU base64 on Linux wraps output at 76 columns by default and -w 0 turns that off; the macOS version does not wrap unless asked. More languages and edge cases: Base64 in JavaScript, Node.js, Python and PHP.
Images, PDFs and any other file go through the file encoder, with data URI and JSON output.
FAQ
How do I Base64 encode a string?
Paste the string into the input box above and copy the result from the output box. In code, convert the string to UTF-8 bytes and encode those bytes: base64.b64encode(s.encode()) in Python, Buffer.from(s).toString("base64") in Node.js.
Why does my Base64 end with = or ==?
Base64 works in blocks of 3 bytes. When the input length is not a multiple of 3, the last block is short and = marks the missing bytes: one = for 2 leftover bytes, == for 1. Padding explained has the details.
Why do I get different Base64 for the same text elsewhere?
Usually a hidden difference in the bytes: a trailing newline (echo adds one), a different charset (UTF-8 vs Latin-1 vs UTF-16) or Unicode normalization. Compare the input byte count shown under the tool.
Is Base64 encoding a way to hide passwords?
No. Base64 has no key and anyone can decode it in a second. Use it to transport data, and use real encryption or hashing to protect it. See encoding vs encryption.
How much bigger does text get after Base64 encoding?
Every 3 bytes become 4 characters, so the output is about 33% larger, plus line breaks if you wrap it. 100 bytes of UTF-8 become 136 characters.