base64 encode & decode online
Encode or decode text with base64. No key needed, fully reversible, and nothing leaves your browser.
Base64 step by step: 3 bytes become 4 characters
Base64 reads your text as bytes, three at a time. Those 24 bits are cut into four pieces of 6 bits; each piece is a number from 0 to 63 and picks one of the 64 characters. If the last group is short, zero bits fill it up and = stands in for the missing characters.
a011010 = 26G000110 = 6V010101 = 21s101100 = 44b011011 = 27G000110 = 68111100 = 60g100000 = 32d011101 = 292110110 = 549111101 = 61y110010 = 50b011011 = 27G000110 = 6Q010000 = 16=padding11 bytes in, 16 characters out: +45 %
Typing in the tool above fills this in. Nothing leaves your browser.
What is Base64?
Base64 turns any bytes into text made of 64 safe characters (A–Z, a–z, 0–9, + and /), so binary data survives e-mail, JSON, XML and URLs. Every 3 bytes become 4 characters, which makes the result about 33 % larger; = fills up the last group. It is defined in RFC 4648 and is not encryption: anyone can decode it.
- Data URIs for images in HTML and CSS
- E-mail attachments (MIME)
- HTTP Basic Auth headers
- JSON Web Tokens (as base64url)
- Kubernetes secrets
- PEM keys and certificates
Why won't my Base64 decode?
Paste what you have. The check tells you what is wrong, what kind of data is inside and shows the decoded result, including images and files.
- Paste text above or try an example.
Standard, URL-safe, MIME and data URI
The same input in the forms you meet in practice. Shown for hello world; type in the box above or in the tool to use your text.
- Standard (RFC 4648)what the tool returns
aGVsbG8gd29ybGQ=- URL-safe (base64url)- and _ instead of + and /, no =
aGVsbG8gd29ybGQ- Without paddingsome APIs drop the =
aGVsbG8gd29ybGQ- MIME (76 per line)like chunk_split(); e-mail, PEM uses 64
aGVsbG8gd29ybGQ=↵- Data URIpaste into a browser or img src
data:text/plain;charset=utf-8;base64,aGVsbG8gd29ybGQ=
The same result in your code
Every snippet encodes hello world to aGVsbG8gd29ybGQ= exactly like the tool, then decodes it back. They are run and compared with the tool before each release.
echo base64_encode('hello world'), "\n"; echo base64_decode('aGVsbG8gd29ybGQ='), "\n";
import base64 print(base64.b64encode("hello world".encode()).decode()) print(base64.b64decode("aGVsbG8gd29ybGQ=").decode())
console.log(Buffer.from("hello world").toString("base64")); console.log(Buffer.from("aGVsbG8gd29ybGQ=", "base64").toString());
const bytes = new TextEncoder().encode("hello world"); console.log(btoa(String.fromCharCode(...bytes))); const back = Uint8Array.from(atob("aGVsbG8gd29ybGQ="), (ch) => ch.charCodeAt(0)); console.log(new TextDecoder().decode(back));
btoa() alone only handles Latin-1; going through TextEncoder makes it UTF-8 like the tool.
import java.nio.charset.StandardCharsets; import java.util.Base64; public class Enc { public static void main(String[] args) throws Exception { System.out.println(Base64.getEncoder().encodeToString("hello world".getBytes(StandardCharsets.UTF_8))); System.out.println(new String(Base64.getDecoder().decode("aGVsbG8gd29ybGQ="), StandardCharsets.UTF_8)); } }
package main import ( "encoding/base64" "fmt" ) func main() { fmt.Println(base64.StdEncoding.EncodeToString([]byte("hello world"))) b, _ := base64.StdEncoding.DecodeString("aGVsbG8gd29ybGQ=") fmt.Println(string(b)) }
printf '%s' 'hello world' | base64 printf '%s' 'aGVsbG8gd29ybGQ=' | base64 -d # Long input: base64 -w 0 (Linux) to avoid line breaks # Windows: certutil -encode file.bin out.txt
Base64 examples and test values
What the tool returns for these inputs (UTF-8). Use them to check your own code. ↵ marks a line break.
| Input | Base64 |
|---|---|
| empty string | empty |
a | YQ== |
ab | YWI= |
abc | YWJj |
hello world | aGVsbG8gd29ybGQ= |
Grüße | R3LDvMOfZQ== |
€ | 4oKs |
🙂 | 8J+Zgg== |
Why your Base64 doesn't match
JWTs, many APIs and URLs use base64url: - and _ instead of + and /, usually without =. A standard decoder misreads or rejects it. The check panel tells you which one you have; base64url tool.
In a URL query a + means a space, so Base64 pasted into a URL loses its plus signs on the way. URL-encode it (%2B) or use base64url.
echo "hello" | base64 encodes six bytes, the text plus a line break, and gives aGVsbG8K. printf '%s' hello | base64 gives aGVsbG8=, the same as the tool.
The tool encodes UTF-8 bytes. "ü" is c3 bc in UTF-8 but fc in Latin-1, so Base64 gives w7w= or /A==. If a decoded result shows ü instead of ü, the charsets got mixed up; fix garbled text.
GNU base64 wraps its output at 76 characters (use -w 0), MIME and PEM wrap too. PHP and most decoders ignore the breaks; strict ones like Java's Base64.getDecoder() reject them (use getMimeDecoder()).
JavaScript's btoa() only accepts characters up to U+00FF and throws on "ü" or emoji, or encodes Latin-1 instead of UTF-8. Turn the text into UTF-8 bytes first, as in the browser example above.
A Base64 string without padding has a length that is not a multiple of 4. PHP and browsers accept that, Python's b64decode() raises "Incorrect padding". Add = until the length is divisible by 4.
Anyone can decode it, no key needed. Kubernetes secrets, Basic Auth headers and "encoded" passwords in config files are readable by everyone who sees them. Use encryption to keep something secret.
Questions about Base64
Is Base64 encryption?
No. Base64 has no key and anyone can decode it, here or with one line of code. It only makes bytes safe to send as text. To keep data secret, encrypt it first and Base64-encode the result.
Why does Base64 end with = or ==?
Base64 works in groups of 3 bytes. If the last group has only 1 or 2 bytes, it gets == or = so the length stays a multiple of 4. The step-by-step view above shows it with your text.
How much bigger does Base64 make data?
About a third: n bytes become 4 × ⌈n / 3⌉ characters, so 3 bytes become 4 and 1 MB becomes about 1.33 MB. With line breaks (MIME) it is a few percent more.
What is the difference between Base64 and base64url?
base64url uses - and _ instead of + and /, and usually drops the = padding, so the result can go into URLs and file names. JWTs use base64url. The bytes are the same.
How do I decode Base64 to an image or file?
Paste it into the check panel above. It recognises PNG, JPEG, GIF, WebP, SVG, PDF and ZIP, shows images directly and lets you save the file. Nothing is uploaded.