Base64 Encode & Decode
Encode text or files to Base64, or decode Base64 back to text, an image or a file. Everything runs in your browser.
How to use this Base64 converter
- Encode text: keep Encode selected and type or paste your text. The Base64 appears on the right as you type. Click Copy.
- Decode Base64: click Decode and paste the Base64 string. Spaces, line breaks, missing
=padding and the URL-safe characters-and_are all accepted. If something is wrong, the message tells you the exact position. - Base64 to image or file: paste the Base64 or a whole data URI in Decode mode. When the bytes are not text, you see what kind of file it is, a preview for images, and a Download file button.
- File or image to Base64: choose or drop a file in the second box. Keep As data URI ticked to get text you can paste straight into HTML
<img src="…">or CSSurl(…). - Swap moves the result into the input and switches the mode, so you can check that a round trip gives back the original.
Your text and files never leave the browser: there is no upload, no log and no storage.
What is Base64?
Base64 writes any bytes using only 64 safe characters: A–Z, a–z, 0–9, + and /, with = for padding. It exists because many systems were built for text only: e-mail, JSON, XML, URLs, HTTP headers and config files. Base64 lets you carry an image, a key or any binary data through them without damage.
It works in groups of 3 bytes. The 24 bits are cut into four 6-bit pieces, and each piece (0–63) picks one character. Here is the word Man:
| Text | M | a | n |
|---|---|---|---|
| Bytes | 77 | 97 | 110 |
| Bits | 01001101 | 01100001 | 01101110 |
| 6-bit pieces | 010011 | 010110 | 000101 | 101110 |
|---|---|---|---|---|
| Value | 19 | 22 | 5 | 46 |
| Character | T | W | F | u |
So Man becomes TWFu. Because 3 bytes always become 4 characters, Base64 text is about 33% larger than the original data. When the last group has only 1 or 2 bytes, the output ends with == or =: Ma → TWE=, M → TQ==.
Base64 variants
| Variant | Characters 62 / 63 | Padding | Where it is used |
|---|---|---|---|
| Standard (RFC 4648) | + / | = | Most APIs, JSON, PEM keys, btoa() |
| URL-safe, Base64URL | - _ | usually none | JWT tokens, URLs, file names, WebAuthn |
| MIME | + / | = | E-mail attachments: line break every 76 characters |
| Data URI | + / | = | data:image/png;base64,iVBOR… in HTML and CSS |
A JWT has three Base64URL parts separated by dots. Paste the first or second part here in Decode mode to read its JSON header or payload, or use the JWT decoder to read the whole token, see when it expires and check its signature.
Base64 in code
| Language | Encode | Decode |
|---|---|---|
| JavaScript (browser) | btoa(String.fromCharCode(...new TextEncoder().encode(s))) | new TextDecoder().decode(Uint8Array.from(atob(b), c => c.charCodeAt(0))) |
| Node.js | Buffer.from(s).toString('base64') | Buffer.from(b, 'base64').toString() |
| Python | base64.b64encode(s.encode()).decode() | base64.b64decode(b).decode() |
| Java | Base64.getEncoder().encodeToString(s.getBytes(UTF_8)) | new String(Base64.getDecoder().decode(b), UTF_8) |
| C# | Convert.ToBase64String(Encoding.UTF8.GetBytes(s)) | Encoding.UTF8.GetString(Convert.FromBase64String(b)) |
| PHP | base64_encode($s) | base64_decode($b) |
| Go | base64.StdEncoding.EncodeToString([]byte(s)) | base64.StdEncoding.DecodeString(b) |
| Linux / macOS shell | echo -n 'text' | base64 | echo 'dGV4dA==' | base64 -d |
| Windows PowerShell | [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes('text')) | [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('dGV4dA==')) |
For URL-safe output: Python base64.urlsafe_b64encode, Java Base64.getUrlEncoder().withoutPadding(), Node.js toString('base64url'), Go base64.RawURLEncoding.
Frequently asked questions
Is Base64 encryption?
No. Base64 is an encoding, not encryption. Anyone can decode it without a key, so it does not hide or protect data. Use it to carry bytes through systems that only accept text, and use real encryption (for example AES or RSA) when the data must stay secret.
Why does Base64 text end with = or ==?
Base64 turns every 3 bytes into 4 characters. When the input length is not a multiple of 3, the last group is filled up with = signs: one = when 2 bytes are left over, two == when 1 byte is left over. Some formats, such as Base64URL in JWTs, leave the = signs out. This decoder accepts both.
How much bigger does data get in Base64?
About 33% bigger: 3 bytes become 4 characters. A 30 KB image becomes about 40 KB of Base64 text. With MIME line breaks every 76 characters it grows by about 2-3% more.
What is the difference between Base64 and Base64URL?
Base64URL uses - instead of + and _ instead of /, and usually has no = padding, so the text is safe in URLs and file names. JWT tokens use Base64URL. Tick URL-safe to encode in Base64URL; the decoder reads both forms automatically.
Why does btoa() fail with "character out of range" in JavaScript?
btoa() only accepts characters 0-255, so text with accents, Chinese characters or emoji fails. Encode the text to UTF-8 bytes first: btoa(String.fromCharCode(...new TextEncoder().encode(text))). This tool always uses UTF-8, which is what most other languages and APIs use too.
How do I convert a Base64 string to an image?
Choose Decode and paste the Base64 text or the full data URI (data:image/png;base64,...). If the bytes are a PNG, JPEG, GIF, WebP, SVG or another image, the tool shows a preview and a Download button that saves the file with the right extension.
Is my data sent to a server?
No. Encoding and decoding run in your browser with JavaScript. Your text and files are not uploaded or stored, so it is safe to use with tokens, keys or private files.