Base64 Encoder / Decoder
-
Free · runs in your browser
-
Nothing is uploaded or stored
-
With ready-to-paste Java code
Paste text to encode it to Base64, or paste Base64 to decode it back to text. The converter picks the direction automatically, handles UTF-8 correctly (accents, Devanagari, emoji), supports the standard, URL-safe and MIME variants, and can encode a file you drop in.
When something fails to decode, it does not just say “invalid input”. It names the problem — the exact character and position, a length that cannot be Base64, padding in the wrong place, or the wrong alphabet — and offers a one-click fix. Paste a JSON Web Token and it splits and decodes the header and payload for you. Everything runs in your browser; nothing you paste is uploaded or stored.
btoa() throws on every one
of them.Base64.getEncoder(),
getUrlEncoder() and getMimeEncoder().exp / iat / nbf shown as dates.data: URI. Decoded output is identified by file signature and images are
previewed.Base64 represents arbitrary binary data using 64 printable characters. Every 3 bytes
(24 bits) are split into 4 groups of 6 bits, and each group becomes one character from the
alphabet A–Z a–z 0–9 + /. When the input length is not a
multiple of 3, the output is padded with = so it stays a multiple of 4 characters.
That 3-to-4 ratio is why Base64 always grows data by about 33%. It exists so binary can travel through channels that only accept text: email bodies, JSON payloads, HTTP headers, XML documents, and source files.
This is worth stating plainly, because it causes real security incidents. Base64 has no key and no secret. Anything encoded with it can be decoded by anyone, instantly, using a page like this one. A Base64-encoded password is a plaintext password with extra steps.
The same applies to HTTP Basic authentication: the Authorization: Basic header
is nothing more than username:password in Base64, which is precisely why Basic
auth must only ever be used over HTTPS.
Since Java 8 the answer is java.util.Base64. It offers three encoders and three
matching decoders, and choosing the wrong pair is a common source of bugs:
// Encode - always name the charset
String encoded = Base64.getEncoder()
.encodeToString(text.getBytes(StandardCharsets.UTF_8));
// Decode - the charset is not optional here either
String text = new String(Base64.getDecoder().decode(encoded),
StandardCharsets.UTF_8);
// URL-safe, unpadded: what JWTs and OAuth values use
String token = Base64.getUrlEncoder().withoutPadding()
.encodeToString(bytes);Three things to know about the variants. getDecoder() throws
IllegalArgumentException on line breaks, while getMimeDecoder()
ignores them — so PEM keys and email attachments need the MIME decoder.
getUrlDecoder() accepts - and _ but not
+ and /. And org.springframework.util.Base64Utils has
been deprecated since Spring 6.0, while
javax.xml.bind.DatatypeConverter was removed in Java 11 along with the rest of
JAXB — both should be replaced with java.util.Base64.
Base64 encodes bytes. A Java String is characters, so something has to
turn characters into bytes first — and if you do not say which encoding, Java uses the
platform default:
text.getBytes() // wrong: platform default
text.getBytes(StandardCharsets.UTF_8) // right
new String(decoded) // wrong: platform default
new String(decoded, StandardCharsets.UTF_8) // rightThe result is the classic bug where everything works on the developer’s machine and accented characters turn to mojibake in production, because the two JVMs had different default charsets. Java 18 made UTF-8 the default via JEP 400, which helps on new applications, but anything running on an older JDK is still exposed.
A JSON Web Token is three URL-safe, unpadded Base64 segments joined by dots:
header.payload.signature. Paste one into the tool and it decodes the first two and
lists the claims. Two points that follow from this:
No. Encoding and decoding happen in your browser with JavaScript. Nothing you paste is uploaded, logged, stored, or placed in the URL, and files you drop in are read locally with the FileReader API. That matters here more than on most tools, because people paste tokens and credentials into Base64 decoders.
No, and this is the most important thing to understand about it. Base64 is an encoding, not encryption: there is no key, and anyone can reverse it in a second. Base64-encoding a password, an API key or a token protects nothing. It exists to carry binary data safely through channels that only accept text.
Because Base64 encodes bytes, not characters, so the result depends entirely on which character encoding produced those bytes. This tool always uses UTF-8. In Java the equivalent mistake is calling text.getBytes() without a charset, which uses the platform default and gives different output on different machines.
Standard Base64 uses + and / as its last two characters, and both break inside URLs, query strings, filenames and cookies. The URL-safe variant defined in RFC 4648 section 5 replaces them with - and _, and usually drops the = padding. JSON Web Tokens use it, as do many Spring Security and OAuth values. Switch the Alphabet control to URL-safe.
The usual causes are a length that is not a valid Base64 length, a character from the other alphabet, line breaks from an email or PEM file, padding that has been stripped or doubled, or a JWT being pasted whole instead of one segment at a time. This tool names the specific problem and the character position rather than reporting a generic failure.
Yes. Paste the whole token and it splits into header, payload and signature, decodes the first two, and lists the claims with exp, iat and nbf converted to readable dates. It cannot verify the signature, because verification needs the secret or public key that only your server holds. Decoding a token never proves it is valid.
About 33% larger, because every 3 bytes become 4 characters, plus padding and any line breaks. A 30 MB file becomes roughly 40 MB of text. That is why storing images as Base64 in a database column or a JSON response is usually a mistake: it costs a third more space and cannot be streamed.
Yes. Open "Encode a file to Base64" and drop a file in. You can output plain Base64 or a complete data: URI ready to paste into CSS or an img tag. Decoded output is also detected by file signature, so an encoded PNG, JPEG, PDF, ZIP or Java class file is recognised and images are previewed.
Other free, client-side tools on javahandson.com: JSON Formatter & Validator, Unix Timestamp Converter, application.properties ↔ application.yml Converter and the MCP Config Generator & Validator.