Base64 Encoder / Decoder
Base64 Encoder / Decoder
Encode text or files to Base64 and decode Base64 strings — instantly, in your browser.
Base64 Encoder / Decoder Tool
How to Use the Base64 Encoder / Decoder
Choose Encode or Decode mode
Click the Encode or Decode pill button at the top of the tool card. The active mode is highlighted in orange.
Type your text or drop a file
For encoding: switch between the Text and File sub-tabs. In Text mode, type or paste any text: it is encoded as UTF-8, so Malay, Chinese and Tamil come out right, and the count shows bytes in and characters out. In File mode, drag a file onto the drop zone or click to browse (up to 5 MB).
Decoding: paste and the tool detects automatically
Paste any Base64 string into the Decode input. The tool works out whether the result is UTF-8 text, an image (shown as a preview, data: URL or not), or other binary data (named by its file signature and offered as a download). The alphabet is read from the input: - and _ tick URL-safe input, + and / untick it, and a string that mixes the two is refused with the position of the first offender.
Copy or download your result
Click Copy to send the result to your clipboard, or Download to save it as a file. Everything runs entirely in your browser — nothing is sent to any server.
Base64 — The Invisible Encoding Standard Powering the Web
What Is Base64 and Why Do APIs Use It?
Base64 represents binary data as ASCII text using a 64-character alphabet: the
26 uppercase letters A–Z, the 26 lowercase letters a–z, the 10 digits 0–9,
and the two symbols + and / — with =
used as padding to align output to a multiple of four characters. The encoding
converts every 3 bytes of binary input into 4 printable output characters,
using exactly 6 bits of information per character. The name comes directly from
this 64-symbol alphabet.
The encoding solved a specific incompatibility: early internet mail could only
carry 7-bit ASCII text, so sending a photograph or a document as an attachment
meant turning arbitrary bytes into printable characters that every SMTP relay
would pass through unmodified. Privacy Enhanced Mail defined that printable
encoding first (RFC 989, February 1987); MIME carried it over as the
base64 Content-Transfer-Encoding in RFC 2045 (November 1996) —
RFC 4648 §3.1 notes that MIME "inherits the encoding from Privacy Enhanced
Mail". RFC 4648 (October 2006) is the standalone definition this tool follows.
Today, Base64 appears in a surprisingly wide range of modern web technologies
that most developers encounter daily without consciously recognising it.
HTTP Basic Authentication encodes username:password
as Base64 and includes it in every request's Authorization header.
JSON Web Tokens (RFC 7519) consist of three Base64URL-encoded
segments joined by dots. Data URIs embed images, fonts, and
other binary assets directly into HTML and CSS: a small icon encoded as
data:image/png;base64,iVBOR... inside a stylesheet eliminates
one HTTP request entirely. API payloads routinely carry
Base64-encoded file attachments, audio samples, and encrypted blobs because
JSON only natively supports text strings. The alphabet difference is the one
that bites: a standard-Base64 decoder fed a Base64URL string fails on the first
- or _, which is why this tool's decoder recognises
that alphabet and ticks URL-safe input for you.
Base64 in Email: MIME, Attachments and Why Encoded Files Are Bigger
The original MIME standard specified that binary email attachments must be Base64-encoded before transmission because the underlying SMTP protocol was designed around a 7-bit ASCII network where bytes with values above 127 would be stripped or corrupted by relay servers. Base64 solves this by representing every possible byte value using only safe, printable characters that every ASCII-compliant relay preserves faithfully.
The cost of this safety is a size overhead. Because Base64 encodes 3 bytes of binary into 4 characters, output is roughly a third larger than the original file: a 1 MB image attachment becomes roughly 1.33 MB in Base64. This explains why email clients warn you that your "1 MB" attachment looks larger in the raw message source. Modern email clients — Outlook, Gmail, Thunderbird — decode Base64 attachments automatically and invisibly, so users never see the encoded form. However, developers building email parsing systems, newsletter platforms, or compliance archiving tools must handle this decoding explicitly.
RFC 2045 §6.8 puts the overhead plainly: Base64-encoded output is "about 33 percent larger" than the input it represents. That single sentence explains a great deal of day-to-day engineering — why a mailbox quota fills faster than the attachments you sent suggest it should, and why an API that accepts Base64 file uploads needs a request-size limit noticeably larger than the biggest file it is meant to accept.
"Base encoding visually hides otherwise easily recognized information, such as passwords, but does not provide any computational confidentiality." — RFC 4648 §12, Security Considerations
Common Developer Use Cases: Images in CSS, JWTs, and API Payloads
CSS data URIs are one of the most visible uses of Base64 in
front-end development. A small PNG icon or SVG graphic can be embedded directly
in a stylesheet as background: url('data:image/png;base64,...'),
eliminating a network request at the cost of a slightly larger CSS file. The
trade-off is arithmetic you can do yourself: the asset grows by about a third
(RFC 2045 §6.8) and can no longer be cached separately, against one fewer
round trip on the critical path. Measure the round trip your own users actually
pay before deciding — on a fast connection the saving is negligible, and inlined
assets are re-downloaded with every change to the stylesheet.
JWT structure: a JWT looks like
xxxxx.yyyyy.zzzzz — three segments separated by dots. The first
is the header (encoding algorithm), the second is the payload (claims such as
user ID, roles, and token expiry), and the third is the cryptographic signature.
All three segments are Base64URL-encoded — meaning they use - and
_ instead of + and /, and omit
= padding (RFC 7515 §2), so the token is safe to include in URLs
and cookies. Paste any JWT segment into the Decode tab of this tool and you can
read the raw JSON header and payload: reading a JWT needs no key at
all, which is exactly why a JWT is not a place to put secrets.
Verifying the signature is the part that needs a key — the issuer's
public key for asymmetric algorithms such as RS256, or the
shared secret for HMAC algorithms such as HS256. The private key or secret is
what signs the token; it is never needed to verify or to read one.
REST API file uploads: when a mobile or web application needs
to transmit a photo, a scanned document, or an audio recording to a REST API
that accepts JSON, Base64 encoding is the conventional approach. The binary
file is encoded and placed in a string field of the JSON request body —
avoiding the more complex multipart/form-data content type. The
trade-off is the 33% size increase and the need for the API server to decode
before processing. Check which of the three the API expects — standard Base64,
Base64URL, or a raw multipart upload — before you ship: the first
two differ in two alphabet characters and in padding, and RFC 4648 §3.3 tells a
strict decoder to reject non-alphabet characters outright, so the wrong variant
fails as a whole payload rather than as a subtle corruption.
What this page does, exactly: text is turned into UTF-8 bytes with
TextEncoder, and files are read as raw bytes; both are then encoded by this
page's own RFC 4648 encoder rather than the browser's btoa(), so the
alphabet, padding and wrapping options apply to files as well as text. On decode,
spaces, tabs and line breaks are skipped, as MIME allows; any other character outside
the alphabet is refused with its position, and so is a string that mixes the standard
and URL-safe alphabets, which atob() would accept once mapped. Missing
padding is accepted, as JWS needs; padding in the wrong place or of the wrong length
is not. If the last character carries non-zero pad bits, which no conforming encoder
writes (RFC 4648 §3.5), the text still decodes and the page says it is not canonical.
The bytes are shown as text only if they are valid UTF-8 with no NUL byte, and a
byte-order mark is reported rather than silently dropped. Everything runs on the
page's main thread, which is why the file encoder stops at 5 MB, about 6.7 MB of
Base64 output.
Why encoding costs you 33%, and where the alphabet changes
Base64 encoding increases file size by approximately 33% — every 3 bytes of binary data becomes 4 Base64 characters.
The "Base" in Base64 refers to the 64-character alphabet used: A-Z (26), a-z (26), 0-9 (10), + and / (2) = 64 total.
JWT uses Base64URL encoding, not standard Base64 — the difference is - instead of + and _ instead of /, making it safe in URLs.
The = padding at the end ensures encoded length is divisible by 4 — you may see one or two = signs, or none where the referring spec drops them, as JWT does.
Three documents, one encoding: RFC 989 (1987) defined it for Privacy Enhanced Mail, RFC 2045 (1996) made it MIME's base64 transfer encoding, and RFC 4648 (2006) is the standalone specification this tool follows.
HTTP Basic Authentication Base64-encodes user:password. RFC 7617 §4 is blunt about what that means: it "results in the cleartext transmission of the user's password" unless the connection is otherwise protected.
The atob() and btoa() JavaScript functions provide native Base64 encoding — but they only handle Latin-1 characters; Unicode requires extra handling. This tool encodes through TextEncoder, so 新加坡 and emoji encode correctly where bare btoa() throws.
RFC 4648 §12 states the security position exactly: Base64 "visually hides otherwise easily recognized information, such as passwords, but does not provide any computational confidentiality."
How this decoder decides: a pasted string of eight or more characters that uses - or _ and never + or / is treated as Base64URL, and URL-safe input is ticked for you. A length that leaves a remainder of 1 when divided by 4 can never be valid Base64 and is refused, and so is a string that uses both + or / and - or _.
RFC 4648 §3.2 requires = padding unless the spec that references it says otherwise — and JWS (RFC 7515 §2) says otherwise, which is why JWT segments never end in =.
Frequently Asked Questions
-
No — Base64 is encoding, not encryption. Encryption scrambles data using a secret key so only authorised parties can read it. Base64 simply converts binary data into a different text representation using a fixed, public alphabet. Anyone with a Base64 decoder (including this tool) can instantly reverse the process without any key. Never use Base64 alone to protect sensitive data — always layer it with proper encryption such as AES-256 if you need confidentiality.
-
Binary data uses 8 bits per byte — 256 possible values. Base64 uses only 64 characters (6 bits of information per character). To represent 3 bytes (24 bits), you need 4 Base64 characters (24 ÷ 6 = 4). This means every 3 bytes become 4 characters — a size increase of one third, or 33.3%, whenever the input length is a multiple of 3 and the output is not wrapped. Padding pushes short inputs well past that: a single byte still becomes 4 characters. Wrapping the output at 76 columns adds a newline on top of that again. This overhead is the unavoidable trade-off for having safe, printable, text-compatible data that travels reliably over any ASCII-safe channel.
-
Standard Base64 uses
+,/, and=— characters that have special meaning in URLs (+is decoded as a space in form data,/is a path separator,=is a key-value delimiter). RFC 4648 §5 defines the URL and filename safe alphabet, which replaces+with-and/with_. Dropping the=padding is a separate question, governed by §3.2: padding must be included "unless the specification referring to this document explicitly states otherwise" — and JWS (RFC 7515 §2) is one specification that states otherwise, which is why JWT segments carry no padding. Use URL-safe mode whenever your Base64 string will appear in a URL, a JWT, a cookie, or any system that processes URLs without additional percent-encoding. -
A data URI is a URL that contains the file contents directly, rather than pointing to an external resource. The format is
data:[MIME type];base64,[encoded data]. For example, a small PNG image embedded in a CSS stylesheet might look likedata:image/png;base64,iVBOR.... Data URIs eliminate a separate HTTP request for small assets, which benefits performance on high-latency networks. This tool's File encoder outputs full data URIs by default (toggle off the "Include data: header" option for raw Base64 only). -
A JWT looks like
xxxxx.yyyyy.zzzzz— three segments separated by dots. Copy the first segment (header) or second segment (payload) and paste it into the Decode tab of this tool. Each segment is Base64URL-encoded (URL-safe alphabet, no padding). If the segment contains-or_, the tool ticks URL-safe input for you before decoding; you can also tick it yourself, and the result re-decodes immediately. The first segment reveals the signing algorithm; the second reveals the claims (user ID, roles, expiry). The third segment is the cryptographic signature — decoding it shows raw bytes, not the original secret. Reading any of this requires no key; only verifying the signature does. -
Base64 encodes every 3 bytes into 4 characters. If the input length is not a multiple of 3, one or two
=padding characters are appended to make the total output length a multiple of 4. One=means 2 bytes were left over in the last group;==means only 1 byte was left. Base64URL as used in JWS omits the padding (RFC 7515 §2) because the decoder can infer the length from the remainder — both padded and unpadded variants decode to exactly the same bytes, and this tool restores the padding before decoding. -
Yes — Base64 can encode any binary file: images (PNG, JPEG, WebP, GIF, SVG), PDFs, audio files, fonts, archives, spreadsheets, or executables. This tool's File tab reads the file's raw bytes and encodes them itself, so you can have a
data:URL (RFC 2397, always standard Base64 with padding) or raw Base64 in either alphabet, with or without padding. Files up to 5 MB are supported, about 6.7 MB of Base64 output. The media type in adata:URL is whatever your browser reports for the file, orapplication/octet-streamwhen it reports none. For larger files, use a command-line tool (base64on Linux/macOS,certutil -encodeon Windows) or a server-side library. -
MIME (Multipurpose Internet Mail Extensions) is the standard that allows email messages to carry attachments, HTML content, images, and other non-ASCII data. RFC 2045 specifies that binary attachments must be encoded using Base64 before transmission, because original SMTP relays only passed 7-bit ASCII bytes safely. Modern email clients decode Base64 attachments automatically. MIME also defines content type headers — such as
image/pngorapplication/pdf— that browsers and email clients use to decide how to handle decoded content. These same MIME types appear in the header of Base64 data URIs. -
A valid standard Base64 string contains only the characters
A-Z,a-z,0-9,+,/, and optionally trailing=padding — and its total length is always a multiple of 4. A valid URL-safe Base64 string uses-and_instead of+and/, and may omit padding. On decode, this tool reads the alphabet from the string and ticks or unticks URL-safe input to match. It shows an error, with the position, for a character outside both alphabets, a mix of the two, misplaced padding or an impossible length, and it flags a string whose last character has non-zero pad bits: that decodes, but no conforming encoder would have written it (RFC 4648 §3.5). When in doubt, paste the string into the Decode tab — a successful decode confirms validity. -
They are removed before decoding, so Base64 copied out of an email source (MIME wraps it at 76 columns, RFC 2045 §6.8) or a PEM file decodes without editing. That is a deliberate leniency: RFC 4648 §3.3 says a decoder MUST reject characters outside the alphabet unless the referring specification allows them, and MIME does allow line breaks. Everything else is strict: a stray character, a mix of the standard and URL-safe alphabets, padding that is not at the end, or a length that leaves a remainder of 1 when divided by 4 produces an error with its position rather than a partial result. Nothing you paste or drop here leaves your browser.
Related News
You may be interested in these recent stories from our newsroom.
-
Apple Loses Its EU Gatekeeper Fight — What the DMA Ruling Actually Changes for Developers
The EU General Court upheld Apple's DMA gatekeeper designation for the App Store and iOS on 8 July 2026. The ruling settles who the rules ap...
-
DuneSlide: Two Cursor Flaws Turn a Zero-Click Prompt Injection Into Code Execution
Cato AI Labs has disclosed DuneSlide — two critical remote-code-execution flaws in Cursor (CVE-2026-50548 and CVE-2026-50549, CVSS 9.8) that...
-
Cloudflare Splits AI Crawlers Into Search, Agent and Training — With New Ad-Page Defaults Coming in September
On 1 July 2026, Cloudflare split AI bot traffic into Search, Agent and Training categories for all customers, including the free tier. From...
Method & sources
How it computes
RFC 4648 encoder written out (not btoa): UTF-8 text (TextEncoder) or raw file bytes, standard or URL-safe alphabet (§4/§5), = padding by default (§3.2) or omitted as JWS does, optional 76-column MIME wrap. Decoder skips only whitespace, refuses other characters, mixed alphabets and misplaced padding with a position, and flags non-zero pad bits (§3.5). data: URLs per RFC 2397.
What this tool implements
- RFC 4648 §10 test vectors pinned in the suite, plus a 200-length byte sweep compared with an independent encoder in both alphabets.
- Strict decoding per RFC 4648 §3.3: characters outside the alphabet are refused with their position; spaces, tabs and line breaks are skipped as MIME allows (RFC 2045 §6.8). A string mixing + / with - _ is refused: atob() would accept it once mapped.
- Padding: written by default (RFC 4648 §3.2); "Omit = padding" produces the JWS form (RFC 7515 §2) and is ticked with URL-safe. On decode, missing padding is accepted, padding anywhere but the end, more than two, or on a length that is not a multiple of 4 is refused.
- Canonical encoding (RFC 4648 §3.5): a last character with non-zero pad bits decodes, as a decoder MAY, and is reported as not canonical.
- data: URLs per RFC 2397, parameters included (charset), default text/plain;charset=US-ASCII, and percent-encoded data when ";base64" is absent; a file's data: URL is always standard Base64 with padding.
- Text: UTF-8 in and out; a lone surrogate (which becomes U+FFFD) and a leading byte-order mark are reported rather than hidden; bytes with a NUL or invalid UTF-8 are treated as binary, named by file signature, previewed if an image, and offered as a download with a hex preview.
- Corrected 2026-11-06: mixed alphabets and non-canonical input accepted silently; data: URLs with parameters refused; URL-safe output could not be padded; file encoding ignored the URL-safe option; the page's description of its own method (btoa/atob, readAsDataURL) replaced with what it now does.
Sources
- RFC 4648, The Base16, Base32, and Base64 Data Encodings (October 2006) — §3.1 line feeds, §3.2 padding, §3.3 non-alphabet characters, §4 base64, §5 base64url, §12 security considerations: https://www.rfc-editor.org/rfc/rfc4648
- RFC 2045, MIME Part One: Format of Internet Message Bodies (November 1996) — §6.8 Base64 Content-Transfer-Encoding, 76-character lines, 'about 33 percent larger': https://www.rfc-editor.org/rfc/rfc2045
- RFC 989, Privacy Enhancement for Internet Electronic Mail (February 1987) — the printable encoding MIME inherited: https://www.rfc-editor.org/rfc/rfc989
- RFC 7515, JSON Web Signature (May 2015) — §2 Base64url Encoding, Appendix C on omitting padding: https://www.rfc-editor.org/rfc/rfc7515
- RFC 7617, The 'Basic' HTTP Authentication Scheme (September 2015) — §4 Security Considerations: https://www.rfc-editor.org/rfc/rfc7617
- RFC 2397, The "data" URL scheme (August 1998): https://www.rfc-editor.org/rfc/rfc2397
- WHATWG HTML Living Standard — btoa() and atob(), forgiving-base64 decode: https://html.spec.whatwg.org/multipage/webappapis.html#atob