Base64 Encoder / Decoder
Encode text or files to Base64 and decode it back, in your browser. UTF-8 safe, URL-safe base64url, data URIs, image preview and clear errors.
data: URL.Type or paste text to encode it to Base64, or switch to Decode to turn Base64 back into text. Text is encoded as UTF-8, so accented letters, other scripts and emoji round-trip correctly. You can also load a file to get its Base64 or a ready-made data URI, and decoded images are previewed. Encoding and decoding run in your browser; nothing you type or load is sent to a server.
How Base64 encoding works
Base64, defined in RFC 4648, turns any sequence of bytes into text made from 64 safe characters. It reads the input three bytes (24 bits) at a time and splits those 24 bits into four groups of 6 bits. Each 6-bit group is a number from 0 to 63, and that number picks one character from the alphabet below. Three bytes in, four characters out.
| Value | Char | Value | Char | Value | Char | Value | Char |
|---|---|---|---|---|---|---|---|
| 0 | A | 16 | Q | 32 | g | 48 | w |
| 1 | B | 17 | R | 33 | h | 49 | x |
| 2 | C | 18 | S | 34 | i | 50 | y |
| 3 | D | 19 | T | 35 | j | 51 | z |
| 4 | E | 20 | U | 36 | k | 52 | 0 |
| 5 | F | 21 | V | 37 | l | 53 | 1 |
| 6 | G | 22 | W | 38 | m | 54 | 2 |
| 7 | H | 23 | X | 39 | n | 55 | 3 |
| 8 | I | 24 | Y | 40 | o | 56 | 4 |
| 9 | J | 25 | Z | 41 | p | 57 | 5 |
| 10 | K | 26 | a | 42 | q | 58 | 6 |
| 11 | L | 27 | b | 43 | r | 59 | 7 |
| 12 | M | 28 | c | 44 | s | 60 | 8 |
| 13 | N | 29 | d | 45 | t | 61 | 9 |
| 14 | O | 30 | e | 46 | u | 62 | + |
| 15 | P | 31 | f | 47 | v | 63 | / |
Worked example: encoding "Go23"
First, each character becomes its byte value and 8 bits:
| Character | Byte (decimal) | Hex | Bits |
|---|---|---|---|
G | 71 | 47 | 01000111 |
o | 111 | 6F | 01101111 |
2 | 50 | 32 | 00110010 |
3 | 51 | 33 | 00110011 |
That is 32 bits. Regrouped into sixes, the last group is short, so 4 zero bits (underlined) are added to fill it:
| 6-bit group | Value | Character |
|---|---|---|
010001 | 17 | R |
110110 | 54 | 2 |
111100 | 60 | 8 |
110010 | 50 | y |
001100 | 12 | M |
110000 | 48 | w |
The first three bytes, "Go2", fill a complete block and become R28y. The fourth byte alone yields two characters, and 2 = signs pad the block to four, giving R28yMw==, exactly what PHP's base64_encode() returns.
What the = padding means
The input length decides the ending. If it is a multiple of 3 bytes there is no padding. One leftover byte gives two characters plus ==; two leftover bytes give three characters plus =. Padding carries no data. It only keeps the output a multiple of 4 characters, so a decoder can find the end even when several encoded values are joined. Many formats drop it, and this decoder adds it back when it is missing.
How much bigger Base64 makes data
Every 3 bytes become 4 characters, so encoded data is about 33% larger than the original:
unpadded length = โ4n รท 3โ characters
| Input bytes | Base64 (padded) | Without padding | Growth |
|---|---|---|---|
| 1 | 4 | 2 | +300.0% |
| 2 | 4 | 3 | +100.0% |
| 3 | 4 | 4 | +33.3% |
| 4 | 8 | 6 | +100.0% |
| 10 | 16 | 14 | +60.0% |
| 100 | 136 | 134 | +36.0% |
| 1,000 | 1,336 | 1,334 | +33.6% |
| 10,000 | 13,336 | 13,334 | +33.4% |
| 1,000,000 | 1,333,336 | 1,333,334 | +33.3% |
Small inputs grow by more because padding rounds them up to a full block. Email (MIME, RFC 2045) also breaks Base64 into lines of at most 76 characters, and the line breaks add more: 1,000,000 bytes become 1,333,336 characters, or 1,368,424 with CRLF line endings. The Wrap at 76 characters option produces that layout (with plain line feeds).
URL-safe Base64 (base64url)
Standard Base64 uses + and /, which have meanings in URLs and file paths. RFC 4648 section 5 defines a "base64url" alphabet that swaps them for - and _. Everything else is identical:
| Variant | "<<???>>" encodes to |
|---|---|
| Standard | PDw/Pz8+Pg== |
| URL-safe | PDw_Pz8-Pg== |
| URL-safe, no padding | PDw_Pz8-Pg |
JSON Web Tokens use base64url without padding for all three of their dot-separated parts, which is why you can read a token's header and payload with the JWT decoder. If you must put standard Base64 in a query string, percent-encode it first (+ would otherwise be read as a space); the URL encoder does that.
Data URIs: embedding files in HTML and CSS
A data URI (RFC 2397) puts a file's contents straight into a URL in the form data:[media type];base64,[data]. This tiny SVG circle:
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><circle cx="4" cy="4" r="4" fill="#217fbf"/></svg>
becomes this 174-character URL, usable as an <img src> or a CSS url():
data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4IiBoZWlnaHQ9IjgiPjxjaXJjbGUgY3g9IjQiIGN5PSI0IiByPSI0IiBmaWxsPSIjMjE3ZmJmIi8+PC9zdmc+
Data URIs save a separate request, but they are about a third larger than the file, cannot be cached on their own, and make HTML and CSS harder to read. They suit small icons and placeholders rather than photos. Load a file in the tool above with Output as data URI ticked to build one.
Base64 is encoding, not encryption
Base64 has no key and no secret. Anyone can decode it, instantly, with this page or a single line of code. Do not use it to hide passwords, API keys or personal data. To store passwords, use a dedicated password-hashing function such as bcrypt or Argon2; to check that a file has not changed, compare a checksum from the hash generator; to keep data secret, use real encryption.
Fixing common decoding errors
| Symptom | Likely cause and fix |
|---|---|
| "Incorrect padding" in other tools | The = signs were stripped. Add them back until the length is a multiple of 4; this page does it for you. |
Invalid character - or _ | The data is URL-safe Base64. Replace - with + and _ with /, or decode here, which accepts both alphabets. |
Spaces where + should be | The value went through a URL or form and + was read as a space. Percent-encode Base64 before putting it in a URL. |
| "รยฉ" instead of "รฉ" | Text was encoded as UTF-8 but decoded as Latin-1. "รฉ" is the two UTF-8 bytes C3 A9 (w6k=); in Latin-1 it is one byte (6Q==). Decode as UTF-8. |
Output ends in K, Cg== or o= | A trailing newline was encoded. echo Go23 | base64 gives R28yMwo= instead of R28yMw==; use printf or echo -n. |
Base64 in code
In JavaScript, btoa() only accepts characters up to U+00FF and throws on anything else, such as "โฌ" or emoji. Convert text to UTF-8 bytes first:
// encode const bytes = new TextEncoder().encode(text); let bin = ''; for (const b of bytes) bin += String.fromCharCode(b); const b64 = btoa(bin); // decode const raw = atob(b64); const out = new TextDecoder().decode(Uint8Array.from(raw, c => c.charCodeAt(0)));
Python and PHP work on bytes directly:
import base64
base64.b64encode("Go23".encode("utf-8")) # b'R28yMw=='
base64.urlsafe_b64encode(b"<<???>>") # b'PDw_Pz8-Pg=='
base64.b64decode("R28yMw==").decode("utf-8")
<?php
base64_encode('Go23'); // R28yMw==
base64_decode($s, true); // strict: false on invalid characters
rtrim(strtr(base64_encode($s), '+/', '-_'), '='); // base64url
On Linux, printf 'Go23' | base64 encodes and base64 -d decodes. Base64 also shows up inside other formats; to inspect the JSON it often wraps, paste the decoded text into the JSON formatter.