Base64 Encoder / Decoder
Encode text to Base64 or decode Base64 back to text — instantly, in your browser.
Encode or Decode Base64 Instantly
This free online tool converts text to and from Base64 — the encoding used to safely represent binary or text data as ASCII, commonly seen in data URIs, Basic Auth headers, and email attachments. Type or paste your text, pick Encode or Decode, and get the result immediately.
How It Works
- Choose Encode or Decode using the toggle above.
- Type or paste your text — conversion happens instantly, no button required.
- URL-safe Base64: check this box to use
-/_instead of+//and drop padding, for Base64 that needs to go inside a URL or filename. The box only affects encoding: decoding accepts both alphabets, with or without padding. - Swap flips the input/output and toggles the mode, so you can immediately verify a round-trip.
- Copy the result to your clipboard with one click.
UTF-8 Safe Encoding
Plain JavaScript's btoa() throws on any character outside the Latin-1 range, which
breaks on emoji, accented letters, and most non-English text. This tool encodes text as UTF-8
bytes first, so any Unicode text — including emoji — encodes and decodes correctly.
The difference is easy to see. In a browser, btoa('café ☕') fails with
InvalidCharacterError: The string to be encoded contains characters outside of the Latin1 range,
because the coffee cup is not a Latin-1 character. This tool first turns the same text into its nine UTF-8 bytes (five for café, one for the space and three for
☕) and returns Y2Fmw6kg4piV.
Even plain btoa('café') gives a different answer (Y2Fm6Q==) because it writes
é as one Latin-1 byte, while UTF-8 uses two bytes. A decoder that expects UTF-8, like this one and most
APIs, would reject that Latin-1 result, so always agree on UTF-8 with the other side.
| Input | Method | Result |
|---|---|---|
café ☕ | encode, UTF-8 (this tool) | Y2Fmw6kg4piV |
café ☕ | plain btoa() | throws InvalidCharacterError |
café | plain btoa() (Latin-1) | Y2Fm6Q== |
How Base64 Works: Groups of Six Bits
Base64 takes the input as bytes and reads it three bytes (24 bits) at a time. Those 24 bits are cut into four
groups of six bits, and each group, a number from 0 to 63, is replaced by one character of the alphabet
A-Z, a-z, 0-9, +, /. Take the text
Man: its bytes are 01001101 01100001 01101110. Regrouped, that is
010011 010110 000101 101110, which is 19, 22, 5 and 46, and those are the characters
T, W, F and u. The live tool agrees: Man becomes
.
TWFu
When the input is not a multiple of three bytes, the last group is padded with zero bits and the output is
filled up to a multiple of four characters with =. A last group that holds one byte gets two
= in the standard form, and a last group that holds two bytes gets one. The padding carries no data; it only tells a
strict decoder how many bytes the last group held.
| Input | Base64 output | Length |
|---|---|---|
M | TQ== | 4 characters |
Ma | TWE= | 4 characters |
Man | TWFu | 4 characters |
Many | TWFueQ== | 8 characters |
Size: About 33% Larger
Every three input bytes become four output characters, so Base64 text is about one third larger than the data it represents (four characters for three bytes is 133%). The numbers from this tool, for text made of single-byte characters, show the pattern: 1 byte gives 4 characters, 100 bytes give 136, 1,000 bytes give 1336 and 3,000 bytes give 4000. The tool prints the result on one line and never inserts line breaks, so the length is exactly what the formula says. Plan for that overhead when you embed Base64 in JSON or in a URL, and remember that text outside plain ASCII takes more than one byte per character before encoding starts.
Standard and URL-Safe Base64 with a Worked Example
The characters + and / mean something in URLs (a plus can stand for a space in a query string and a slash
separates path segments), and = separates keys from values. The URL-safe variant swaps them for
- and _ and leaves the padding off. The text >>>??? is a good test because its
bytes happen to produce both troublesome characters:
| Input | Option | Output |
|---|---|---|
>>>??? | box off (standard) | Pj4+Pz8/ |
>>>??? | box on (URL-safe) | Pj4-Pz8_ |
Both forms decode to the same text here, and the decoder does not need the box to be ticked: it converts - and
_ back, strips spaces and line breaks, and restores the missing padding before decoding. That is why a value
copied from a JWT or a URL works without any clean-up. If you need to put Base64 inside a URL query value and keep the standard alphabet,
percent-encode it instead with the URL encoder.
Base64 Is Encoding, Not Encryption: Reading a JWT Segment
Anyone can reverse Base64 without a key, so it hides nothing. A good illustration is a JSON Web Token: its first two dot-separated parts are URL-safe Base64 of JSON. Paste the first part of a typical token, in Decode mode:
| Input | Mode | Output |
|---|---|---|
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 | Decode | {"alg":"HS256","typ":"JWT"} |
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFkYSIsImlhdCI6MTUxNjIzOTAyMn0 | Decode | {"sub":"1234567890","name":"Ada","iat":1516239022} |
The decoded header says the token is signed with HS256. The second part decodes to the claims, and none of it is secret. What protects a token is the signature in the third part, which this page does not check; use the JWT decoder to inspect a whole token and the JWT encoder and verifier for signing. If the decoded text is JSON, run it through the JSON formatter to read it comfortably.
Where You Meet Base64: Headers, Data URIs and JSON Fields
An HTTP Basic Authorization header is the text user:password in Base64. Encoding ada:s3cret here gives
, so the header is YWRhOnMzY3JldA==Authorization: Basic . A data URI embeds content in a URL:
YWRhOnMzY3JldA==data:text/plain;base64, is the text SGVsbG8=Hello. JSON documents carry small binary values (or whole
documents) as Base64 strings: the JSON text {"id":1,"ok":true} becomes .
Remember that this tool converts text. It has no file picker, so for an image or a PDF you need a tool that reads the file's bytes.
eyJpZCI6MSwib2siOnRydWV9
When Decoding Fails
The tool shows an inline message instead of guessing. Three situations produce it. A string whose length leaves a single character over a
multiple of four (such as SGVsb, five characters) cannot be valid, and the browser reports that the string
is not correctly encoded. A character outside the alphabet, such as * in SGVs*G8=, gives the same message. And Base64
of binary data, such as the start of a JPEG (/9j/4AAQ), decodes to bytes that are not valid UTF-8, so the tool reports that
the decoded data was not valid text rather than showing garbage. The output box is cleared when an error appears, so an error is never shown next to an old result. A value without padding, like SGVsbG8, decodes fine to
.
Hello
Privacy
All encoding and decoding happens entirely in your browser using JavaScript. Nothing you type is ever sent to a server.
Base64 Encoding — Options Explained
Base64 has a couple of variants that matter depending on where the encoded text ends up. Here's what each option on this page does.
Standard Base64
Uses the characters A-Z a-z 0-9 + / with = padding at the end. This is the default and matches what most libraries and command-line tools (like base64) produce.
URL-Safe Base64
Replaces + with - and / with _, and omits padding — because standard Base64's characters have special meaning in URLs and filenames. Common in JWTs and URL parameters.
UTF-8 Text Handling
Text is first converted to its UTF-8 byte representation before Base64 encoding, and decoded the same way in reverse — so accented characters, symbols, and emoji round-trip correctly.
Invalid Input Handling
If the Base64 input contains invalid characters or can't be decoded as valid UTF-8, the tool shows an inline error instead of producing garbled or silently wrong output.
Who Uses This Tool?
API Developers
Decode a Basic Auth header, a JWT segment, or a Base64-encoded field in an API response to see its real value during debugging. If the decoded value turns out to be an escaped JSON string full of \" and \n, run it through the JSON Escape / Unescape tool to read it as plain text.
Backend Developers
Encode config values, tokens, or small binary blobs into Base64 text for embedding in JSON, environment variables, or config files.
Web Developers
Build or inspect small inline data URIs (data:text/plain;base64,...) without reaching for a script or command-line tool.
Students & Learners
See exactly how Base64 encoding works, character by character, while learning about data encoding and transport formats.
Frequently Asked Questions
What is Base64 encoding?
Base64 is a way to represent binary or text data using only 64 printable ASCII characters (A-Z a-z 0-9 + /), commonly used when data needs to be safely embedded in text-based formats like JSON, XML, URLs, or email.
Is Base64 encryption?
No. Base64 is an encoding, not encryption — it provides no confidentiality. Anyone can decode Base64 text back to its original form instantly, which this tool demonstrates. Never use Base64 alone to protect sensitive data.
What's the difference between standard and URL-safe Base64?
Standard Base64 uses + and /, which have special meaning inside URLs. URL-safe Base64 replaces them with - and _ and drops the = padding, so the result can be used directly inside a URL or filename without further encoding.
Why did decoding fail with an error?
Decoding fails if the input contains characters outside the Base64 alphabet, or if the decoded bytes aren't valid UTF-8 text. This usually means the input is truncated, corrupted, or wasn't actually Base64 to begin with.
Is my data uploaded anywhere?
No. All encoding and decoding happens locally in your browser with JavaScript. Nothing is sent to a server.
How much bigger is Base64 than the original data?
About one third. Every 3 bytes become 4 characters, so 1,000 bytes of text become 1336 characters, including padding. The tool does not add line breaks, so the length follows that formula exactly.
Can I decode a Base64 image or file here?
Not into a file. This tool turns Base64 into UTF-8 text only. If the Base64 holds binary data, such as an image or a PDF, the decoded bytes are not valid text and the tool shows an error instead of showing broken characters. It also has no file picker for encoding.
Why does decoding work without the = padding?
The padding only tells a strict decoder how many bytes the last group held. This tool puts the missing = back before decoding, and it also accepts the URL-safe characters - and _ whether or not the URL-safe box is ticked, so values copied from JWTs and URLs decode as they are.
Related Tools
- URL encoder and decoder: encode or decode URLs and query strings.
- JSON escape and unescape tool: escape or unescape a JSON string.
- JWT decoder: read the Base64URL parts of a token.
- JWT encoder and verifier: create and verify signed tokens.
- cURL to code converter: turn a cURL command into fetch(), Python requests or Node axios code.
- Compare two JSON documents: compare two decoded payloads and see exactly which fields differ.
- JSONPath tester: pull a single claim out of a decoded JWT payload.
- JSON formatter and fixer: validate, format and repair JSON before you use it here.
- All JSON tools: every free tool listed on one page.
Built by Deepak Kumar — a developer who wanted a JSON tool that respects your privacy. All processing happens in your browser. Your data never leaves your device.