oktools

Base64 Encoder & Decoder

Encode text or a file to Base64 and decode Base64 back to text, in the standard or the URL-safe (base64url) alphabet. Text goes through UTF-8, so accents and emoji survive the round trip. Drop a file to get its Base64 or a data: URI, and download decoded Base64 as a file. Everything runs in your browser.

Mode:
Encoding:

0

0

How it works

Base64 works on bytes, not characters, so the first step for text is to turn it into bytes. The encoder writes the input as UTF-8 with TextEncoder, then takes the bytes three at a time and maps each 24-bit group onto four characters from the 64-character alphabet, padding the last group with = when the byte count is not a multiple of three. Encoding the UTF-8 bytes rather than the characters is why an accented letter or an emoji comes out as two to four bytes’ worth of Base64 instead of failing: the browser’s bare btoa accepts only Latin-1, which is where most hand-rolled encoders break.

Decoding is the reverse with the rough edges taken off first. A data: URL prefix is removed and its media type remembered, whitespace and line breaks are stripped so MIME-wrapped input decodes, the base64url characters - and _ are mapped back to + and /, and any padding is dropped and worked out again. Two checks then run: a character outside the alphabet is reported as such, and a length of 4n+1, which no sequence of bytes can produce, is reported as a truncated string. The bytes are read as UTF-8 with the strict decoder, so binary data is identified rather than printed as a row of replacement characters.

A file opened or dropped in Encode mode is read in the browser with FileReader and shown as its Base64, or as a complete data: URL carrying the file’s own media type. In Decode mode a dropped .b64 or .txt file is read as text, and Download as file writes the decoded bytes out, named from the data: URL’s type, a recognised file signature (PNG, JPEG, GIF, PDF, ZIP), .txt for text or .bin otherwise.

Examples

Encode text with accents and emoji

Seven characters become eleven bytes once written as UTF-8 — é takes two and the emoji four — which is why the Base64 is longer than the text suggests. Decoding it gives the same seven characters back.

Input
héllo 🙂
Output
aMOpbGxvIPCfmYI=

Encode a value for a URL or a JWT in base64url

Standard Base64 gives dXNlcjpwQHNzL3cwcmQ/, with a slash that a server would read as a path separator. URL-Safe swaps + and / for - and _ and drops the = padding, which is the form JWT segments and most API tokens use.

Input
user:p@ss/w0rd?
Output (URL-Safe)
dXNlcjpwQHNzL3cwcmQ_

Decode a data: URL

The data: prefix is stripped before decoding and its media type is kept, so Download as file would save this as decoded.txt. An image pasted the same way is identified as binary and offered for download instead of being printed.

Input
data:text/plain;charset=utf-8;base64,SGVsbG8sIHdvcmxk
Output
Hello, world

Spot a truncated string

Four characters carry three bytes, so a length of 4n+1 cannot come from any byte sequence; the message says so rather than reporting a generic failure. A character outside the alphabet, such as a stray asterisk, is named the same way.

Input
QUJDR
Result
Base64 is truncated — one character too many or too few.

Supported formats

  • Standard Base64 (RFC 4648 §4)The + / alphabet with = padding, as used in MIME, PEM and most APIs. The output is one unbroken line unless wrapping is ticked.
  • URL-safe Base64 (RFC 4648 §5)- and _ in place of + and /, with the padding dropped. Decoding accepts either alphabet, or a mixture of the two, without being told which.
  • MIME line wrappingWrap output at 76 characters breaks the encoded text into lines as RFC 2045 requires for email bodies. Decoding ignores line breaks and every other kind of whitespace.
  • data: URLsEncode output can be a data:<type>;base64,… URL: a text input gets text/plain;charset=utf-8 and a file gets its own media type. Decoding strips the prefix and keeps the type for the download.
  • Files up to 10 MBAny file can be opened or dropped for encoding, and decoded bytes can be saved as a file, with the extension taken from the data: type, the file signature or .txt for text.

Use cases

  • Embed an image or a font in CSS or HTMLDrop the file with Output as data: URL ticked and paste the result into src or url(): no separate request and no path to break when the page moves.
  • Read the Base64 in a config, header or request bodyKubernetes Secrets, Basic authentication headers and JSON fields that carry binary all use Base64; paste the value to see what is inside it.
  • Recover a file from an API response or a logPaste the Base64 of a PDF or an image and press Download as file to get the bytes back as a file with the right extension.
  • Prepare a value for a URL or a JWTEncode in the URL-safe alphabet so no + / or = needs percent-encoding on its way into a query string, a path or a token segment.
  • Check a hand-rolled encoderCompare its output against this page for text with accents or emoji; a Latin-1 encoder shows itself at the first character outside ASCII.

Limitations

  • Text is always UTF-8Base64 of Windows-1252 or UTF-16 text decodes as bytes, not as text, and is offered as a download; open the file with the right encoding to read it.
  • Files over 10 MB are refusedThe Base64 alone would be over 13 MB of text box. Use base64 or openssl base64 on the command line for larger files.
  • Binary output is a download, not a viewBytes that are not UTF-8 text are not shown in the output box, and there is no hex dump; Download as file is the way to get them.
  • Only the two Base64 alphabetsBase32, Base85, hexadecimal and uuencode are not read or written; those need a tool of their own.
  • Decoding is permissive by designWhitespace, missing padding and a mixed alphabet are all accepted, so the page says whether a string decodes, not whether it is strictly valid RFC 4648 Base64.

Frequently asked questions

How do I encode text to Base64?

Paste the text into the input box with Encode selected and the Base64 appears immediately. Switch to Decode and paste a Base64 string to get the original text back — switching keeps what you typed and converts it the other way. Swap moves the output back to the input so you can check a round trip.

Can I Base64-encode a file or make a data URI?

Yes. Press Open file or drop a file onto the input with Encode selected and its Base64 appears in the output. Tick "Output as data: URL" to get the full data:<type>;base64,… form that goes straight into an <img src>, a CSS url() or a JSON field. In Decode mode a data: URL prefix is stripped automatically, and Download as file writes the decoded bytes out as a file — the way to recover an image or PDF from a Base64 string.

Is Base64 encryption?

No, and treating it as such is a real security mistake. Base64 is a reversible encoding with no key involved — anyone can decode it in seconds, as this page demonstrates. It exists to carry binary data through channels that only accept text, such as a JSON field, a data URI or an email attachment, not to hide anything.

Why does my Base64 string end in one or two equals signs?

Base64 encodes three bytes into four characters, so when the input length is not a multiple of three the last group is padded out with = to keep the length a multiple of four. One byte left over gives two equals signs, two bytes give one, and an exact multiple gives none.

What is URL-safe Base64 and when do I need it?

Standard Base64 uses + and /, which both have meanings inside a URL, and = which has to be escaped in a query string. URL-safe Base64 (base64url, RFC 4648 §5) swaps them for - and _ and drops the padding. Pick it here when the value goes into a path, a query parameter or a JWT. Decoding accepts either alphabet automatically, so you do not have to know which one you were handed.

What does "Wrap output at 76 characters" do?

MIME (RFC 2045) requires Base64 in email bodies to be broken into lines of at most 76 characters, and some tools such as openssl base64 and PEM files wrap at 64 or 76 by default. The checkbox writes the output in 76-character lines for those destinations. It changes only the layout, not the data: decoding here ignores line breaks and whitespace, so wrapped and unwrapped input decode to the same bytes.

Does it handle accented characters and emoji correctly?

Yes. The text is encoded as UTF-8 before being Base64-encoded, and decoded back through UTF-8, so accents, CJK characters and emoji survive a round trip intact. The raw btoa function in a browser throws on anything outside Latin-1, which is why hand-rolled Base64 often breaks on the first emoji. If the decoded bytes are not valid UTF-8 the tool says so instead of printing replacement characters — that usually means the Base64 is a file, which Download as file will give you.

Why does my Base64 fail to decode?

Usually because something was lost in transit: a line break in the middle of the string, a URL that percent-encoded the + signs into spaces, or a truncated copy. Whitespace, missing padding and either alphabet are handled for you here, so the tool reports two real problems: a character outside the Base64 alphabet, or a length that no byte sequence could produce, which means the string was truncated.

Is my data uploaded to a server?

No. The whole tool is JavaScript running in your own browser, so nothing you type, paste or open as a file is sent over the network, written to a log or attached to an analytics event. You can confirm it by opening the network tab and watching it stay empty while you work.