How to use the Base64 Encode / Decode
- 1
Type or paste
Put plain text in the input to encode, or a Base64 string to decode.
- 2
Encode or decode
Press Encode → or ← Decode. Tick URL-safe if the encoded result will go in a URL or file name.
- 3
Or convert a file
Pick a file with “File → Base64” to get a complete data URL.
- 4
Copy the output
Use “Copy output”. The status line shows the byte sizes before and after encoding.
Features
UTF-8 first
Text is turned into UTF-8 bytes before encoding, so emoji and Indian scripts work.
URL-safe output
Replaces + with -, / with _ and removes = padding.
Tolerant decoder
Ignores whitespace and line breaks, accepts both alphabets and missing padding, and strips a data: prefix.
File to data URL
Any file becomes data:<type>;base64,… ready for img src or CSS.
Strict text check
Decoding refuses results that are not valid UTF-8 text instead of showing garbage.
Local
Files and text are processed in the browser only.
Who uses it — and for what
Developers
Build Basic-auth headers, inspect API payloads and decode config values.
Front-end developers
Inline small icons as data URLs to save a request.
Testers
Decode tokens and encoded fields while debugging.
Email builders
Understand Base64 parts in raw email source.
What Base64 is for
Base64 turns any bytes into 64 safe text characters (A–Z, a–z, 0–9, + and /). It is used to send binary data through systems that only handle text: email attachments, data URLs for images in CSS or HTML, JSON payloads, basic-auth headers and JWT tokens. It is encoding, not encryption — anyone can decode it, so never use it to hide passwords.
Encoded output is about 33% larger than the original. The URL-safe variant replaces + and / with - and _ and drops the = padding, so it can sit in URLs and file names.
Why UTF-8 matters
The browser’s built-in btoa() fails on characters outside Latin-1, such as ₹, emoji or Hindi text. This tool converts text to UTF-8 bytes first, so “नमस्ते 👋” encodes and decodes correctly, matching what servers in Node.js, Python and PHP produce.
How Base64 works, step by step
- The input is turned into bytes. For text, this tool uses UTF-8.
- The bytes are taken three at a time — 24 bits.
- Those 24 bits are split into four groups of 6 bits, each a number from 0 to 63.
- Each number picks a character from the alphabet
A–Z,a–z,0–9,+,/. - If one or two bytes are left over at the end, the last group is padded with zero bits and
=marks the missing bytes.
That is where the familiar size cost comes from: 4 output characters for every 3 input bytes, about 33% more. A 30 KB image becomes roughly 40 KB of text, before any line breaks some systems add. Gzip on a server recovers some of that, but Base64 data is still larger than the raw file.
When to use Base64 — and when not to
| Good fit | Poor fit |
|---|---|
| Tiny icons or SVGs inlined in CSS to avoid a request | Large photos — they bloat HTML or CSS and cannot be cached separately |
| Binary data inside JSON or XML | Storing files in a database text column when a file store is available |
| Email attachments (MIME does this automatically) | Hiding secrets — Base64 is not encryption |
| Tokens in URLs, using the URL-safe alphabet | Shortening data — it always makes it longer |
JSON Web Tokens use URL-safe Base64 without padding for their three parts; paste a token into the JWT Decoder to read the header and payload properly. For images, Image to Base64 adds previews and ready-made CSS and HTML snippets. Percent-encoding, the other common way to make data URL-friendly, is covered by URL Encode / Decode.
Worked examples
Padding in action
| Text | Bytes | Base64 | URL-safe |
|---|---|---|---|
| Hi | 2 | SGk= | SGk |
| Hi! | 3 | SGkh | SGkh |
| Hi!! | 4 | SGkhIQ== | SGkhIQ |
| >>>??? | 6 | Pj4+Pz8/ | Pj4-Pz8_ |
Every 3 bytes become 4 characters. When the input is not a multiple of 3, = signs pad the last group. The last row shows why URL-safe matters: + and / have special meanings in URLs and file paths.
Unicode text
नमस्ते 👋 is 23 UTF-8 bytes (six Devanagari code points at three bytes each, a space, and a four-byte emoji) and encodes to:
4KSo4KSu4KS44KWN4KSk4KWHIPCfkYs=₹500 is 6 bytes and becomes 4oK5NTAw. Decoding these strings in Node.js, Python or PHP gives the same text back, because they also use UTF-8.
A Basic-auth header
HTTP Basic authentication sends username:password in Base64. user:pass encodes to dXNlcjpwYXNz, giving the header Authorization: Basic dXNlcjpwYXNz. Anyone who sees the header can decode it in a second — which is why Basic auth must only be used over HTTPS. Use made-up values like these when testing, never real credentials.
Pro tips
- The decoder already accepts URL-safe input and missing = padding, so you can paste JWT parts or URL tokens directly.
- If decoding says the result is binary, the data is probably a file (an image, a PDF, a zip) rather than text — that is expected.
- Line-wrapped Base64 from emails or PEM files decodes fine, because whitespace is removed first.
Glossary
- Padding
- The = characters added at the end so the output length is a multiple of four.
- URL-safe Base64
- A variant (often called base64url) that uses - and _ instead of + and /.
- Data URL
- A URL that contains a file’s content directly, like data:image/png;base64,….
- UTF-8
- The standard way of storing Unicode text as bytes, using one to four bytes per character.
Frequently asked questions
Is Base64 secure?
No. It is a reversible encoding with no key; treat Base64 data as plain text.
How do I convert an image to Base64?
Use “File → Base64”. You get a data URL you can paste into an img src or CSS background.
Why does decoding fail?
The input may be cut off, contain stray characters, or not be Base64 at all. URL-safe characters (- and _) are accepted automatically when decoding.
Why does btoa() in my code throw an error for Hindi text?
The browser’s btoa only accepts characters with codes up to 255. Convert the string to UTF-8 bytes first (for example with TextEncoder), which is what this tool does.
Do I need to tick URL-safe to decode a URL-safe string?
No. The decoder maps - and _ back automatically and restores padding, whatever the checkbox says. The option only changes encoding.
Can I turn Base64 back into a file?
This page decodes to text only. For an image, pasting the full data URL into the address bar shows it in many browsers, or use Image to Base64 for image-specific options.
Last updated 2026-11-28 · Built by Vinayak Agarwal · Part of Developer & Web (77 tools)