Base64 Encode
Type text and it is converted to Base64 instantly, with all characters handled as UTF-8. You can also convert images and files to Base64 and get a data URI ready to paste into HTML or CSS. To turn Base64 back into text or an image, switch to the decode tab above or use Base64 Decode. Everything runs in your browser – nothing is uploaded to a server.
How to use the Base64 encoder
- Text to Base64: choose “Text” and type or paste your content; the result appears below as you type.
- Image or file to Base64: choose “File”, then pick a file or drag it in (up to 10 MB). With “Output as data URI” ticked you get
data:image/png;base64,…, ready for a web page; images are previewed. - Options: “URL-safe (- and _ instead of + and /)” for URLs and JWT, “Remove padding (=)” to drop the trailing =, and “Line breaks every 76 characters (MIME)” for email (MIME).
- Use “Copy” or download the result, or “Send to decode” to decode it again and check.
What is Base64?
Base64 is a way to turn any binary data into text using only 64 characters: A–Z, a–z, 0–9, + and /, plus = for padding. Many channels – email, JSON, URLs – are designed for plain text, and raw images or special characters can break them. Encoding to these 64 “safe” characters lets data travel between systems, and the receiver decodes it back.
How Base64 encoding works
Base64 splits every 3 bytes (24 bits) into 4 groups of 6 bits, and each 6-bit value (0–63) maps to one character. For the text Man:
| Step | Value |
|---|
- Original text |
Man - Bytes (ASCII) | 77, 97, 110
- In binary |
01001101 01100001 01101110 - Groups of 6 bits |
010011 010110 000101 101110 - As decimal | 19, 22, 5, 46
- Base64 characters |
TWFu
So Man becomes TWFu. Values 0–25 map to A–Z, 26–51 to a–z, 52–61 to 0–9, 62 to + and 63 to /. Non-English text must first be turned into bytes; this tool always uses UTF-8, so “你好” becomes 5L2g5aW9.
Padding (=), size and URL-safe Base64
When the data length isn’t a multiple of 3, the last group is padded with =: Ma becomes TWE= and M becomes TQ==. Because every 3 bytes become 4 characters, Base64 output is about 4/3 of the original size (33% larger) – fine for small icons, wasteful for large files.
The standard + and / have special meanings in URLs, so URLs, file names and JWT use Base64URL: - instead of +, _ instead of /, usually without =. Tick “URL-safe” and “remove padding” to produce it.
Common uses of Base64
- Inline images (data URI): put small icons as
data:image/png;base64,…in an HTMLimgor CSSbackgroundto save a request. - Email attachments: MIME sends attachments and non-ASCII text as Base64, wrapped every 76 characters.
- JWT: the header and payload of a JSON Web Token are Base64URL-encoded JSON.
- HTTP Basic authentication:
user:passwordis Base64-encoded in theAuthorization: Basic …header – encoded, not encrypted, so always use HTTPS. - Binary data in JSON, XML or config files: certificates and keys in PEM format are Base64.
Base64 encoding in each programming language
| Language / tool | Text to Base64 (UTF-8) |
|---|---|
| JavaScript (Node.js) | Buffer.from(text).toString('base64') |
| JavaScript (Web API) | btoa(String.fromCharCode(...new TextEncoder().encode(text))) |
| Python | base64.b64encode(text.encode()).decode() |
| Java | Base64.getEncoder().encodeToString(text.getBytes(StandardCharsets.UTF_8)) |
| C# | Convert.ToBase64String(Encoding.UTF8.GetBytes(text)) |
| PHP | base64_encode($text) |
| Linux / macOS | base64 file.txt |
The browser’s built-in btoa() only accepts Latin-1 characters, so encode other text to UTF-8 bytes with TextEncoder first. For URL-safe output use base64.urlsafe_b64encode() in Python, Base64.getUrlEncoder() in Java or toString('base64url') in Node.js.
Frequently asked questions
Is Base64 encryption?
No. Base64 is only an encoding with public rules – anyone can decode it, so it cannot protect passwords or secrets. Use an encryption algorithm such as AES when you need confidentiality.
What does the = at the end of Base64 mean?
It is padding. Base64 turns every 3 bytes into 4 characters; when the data length is not a multiple of 3, one or two = fill the last group. Some formats such as JWT leave it out and add it back when decoding.
Why does another tool give a different result for the same text?
Text has to be turned into bytes first, and different character encodings give different bytes. This tool uses UTF-8, the most common one; a tool using UTF-16 or a legacy encoding will produce different Base64.
How much bigger does data get after Base64 encoding?
About 4/3 of the original, i.e. 33% larger, plus a little more if lines are wrapped every 76 characters. A 30 KB image becomes about 40 KB of Base64.
Is my data uploaded?
No. Text and files are converted directly in your browser and are never sent to this site or any third-party server.
- Base64 Decode: turn Base64 back into text, images or files.
- URL encoder: make text safe for URLs.
- UUID generator: generate v4/v7 unique IDs.