Turn text or a file into Base64. You need it whenever part of the stack only accepts ASCII: a Basic Auth header, a data URI, a mail attachment. Encoding runs in this tab, so a credential you paste here is not sent anywhere.
Hello World!
This is a test for Base64 Encoder. SGVsbG8gV29ybGQhClRoaXMgaXMgYSB0ZXN0IGZvciBCYXNlNjQgRW5jb2Rlci4= Encode bytes before they cross a text-only channel. SMTP, JSON string fields and HTTP headers carry ASCII safely but can corrupt raw binary. Base64 writes every 3 bytes as 4 ASCII characters, so the data arrives intact.
Encode a small icon and paste it into a stylesheet as a data: URL instead of making another request. Keep this for files of a few KB, since the encoded string is about 33% larger than the file.
Accented characters and emoji are converted to UTF-8 bytes before encoding, so they decode back unchanged. For example, é becomes the two bytes C3 A9.
const text = "Hello, wörld! 🌍";
// Node.js: Buffer handles any Unicode string
const encoded = Buffer.from(text, "utf8").toString("base64");
console.log(encoded); // SGVsbG8sIHfDtnJsZCEg8J+MjQ==
// Browser: btoa() only accepts Latin-1, so UTF-8 encode first
const bytes = new TextEncoder().encode(text);
const browserEncoded = btoa(String.fromCharCode(...bytes));
console.log(browserEncoded === encoded); // true
// URL-safe variant (RFC 4648 section 5), no padding
console.log(Buffer.from(text).toString("base64url")); String.fromCharCode(...bytes) throws on very large inputs; loop in chunks or use Uint8Array.prototype.toBase64() where available.
<?php
$text = "Hello, wörld! 🌍";
$encoded = base64_encode($text);
echo $encoded, PHP_EOL; // SGVsbG8sIHfDtnJsZCEg8J+MjQ==
// URL-safe variant: swap + and /, strip = padding
$urlSafe = rtrim(strtr($encoded, '+/', '-_'), '=');
echo $urlSafe, PHP_EOL;
// Encode a file, for example an image
// $encoded = base64_encode(file_get_contents('logo.png')); import base64
text = "Hello, wörld! 🌍"
# b64encode works on bytes, so encode the string as UTF-8 first
encoded = base64.b64encode(text.encode("utf-8")).decode("ascii")
print(encoded) # SGVsbG8sIHfDtnJsZCEg8J+MjQ==
# URL-safe variant uses - and _ instead of + and /
print(base64.urlsafe_b64encode(text.encode("utf-8")).decode("ascii"))
# From the shell: echo -n "hello" | base64 Without -n, echo appends a newline, so the output ends in Cg== and does not match what other tools produce.
Every 3 input bytes become 4 output characters, drawn from a 64-symbol alphabet (A-Z, a-z, 0-9, + and /). That ratio is where the 33% growth comes from. If the input length is not a multiple of 3, = padding fills out the last group, which is why so many encoded strings end in one or two equals signs. The spec is RFC 4648.
The same RFC defines base64url, which swaps + and / for - and _ so the value survives in URLs, filenames and JWTs. Padding is usually dropped there too. However, a decoder for one alphabet rejects the other. Be sure to check which one the receiving side expects before you ship, because a token that looks fine but will not decode is usually in the wrong alphabet.
This tool follows the specifications below. Read them when you need the exact normative wording, for example to settle an edge case between two implementations.
Base64 represents binary data as ASCII text so it can pass through systems that expect text: JSON, XML, email, HTTP Basic authentication headers and data URIs.
Yes. Text is converted to UTF-8 bytes before Base64 encoding, so any character works and decodes back correctly. For example, é encodes as w6k=.
No. Anyone can reverse Base64 without a key, so it offers no security. Use it to move data through text-only channels, and use encryption when the data has to stay secret.
Base64 writes every 3 bytes as 4 characters, so the output is about 33% larger, plus up to two = padding characters. For example, a 30 KB file becomes about 40 KB of text.
Yes. Click Upload File to load a file and encode its contents. For images, use Image to Base64, which also produces a ready-to-use data URI.
To read an encoded string, use the Base64 decoder. For pictures specifically, Image to Base64 produces a data URI you can paste into CSS.