Skip to content
FmtTools

Base64 Encoder and Decoder

RFC 4648 Base64 in standard, URL-safe and MIME framings, with a decoder that identifies what it decoded: a PNG, a JWT, a data URI, a PEM certificate, or text — plus the non-canonical encodings that break equality checks.

Alphabet

Alphabet

Read input as

Line wrapping

Plain text

Input bytes 55Expected output 76

Base64

Rm10VG9vbHMg4oCUIGVuY29kZSDigqwzNy41MCBvciDml6XmnKzoqp4gaW4gb25lIGNsaWNrLg==
Characters 76Overhead 38.2%Groups of 3 bytes 19
Source bytes
55

UTF-8 encoding length

Output characters
76

Excludes line breaks

Including line breaks
76
Size overhead
+38.2%

4 characters per 3 bytes is +33.3%

Full 3-byte groups
19
Padding characters
2

Last group was short

Three bytes become four characters, and the remainder is where bugs live

Base64 maps each group of three input bytes to four characters drawn from a 64-character alphabet, six bits per character. When the input is not a multiple of three, one or two = characters pad the output. That padding is a length signal, not data, and it is the source of most of the pain: base64url, defined in RFC 4648 §5 and used by JWTs, swaps + and / for - and _ and normally omits padding entirely.

The encoder handles UTF-8 text correctly — the common failure with atob and btoa is that they operate on Latin-1 code units, so an accented character either throws or produces bytes that no longer decode to the original. Encoding goes through TextEncoder, so emoji and non-Latin scripts survive the round trip, and a hex input mode is offered for byte-exact work.

The decoder does more than produce text. It reports the variant it accepted, whether the trailing bits were canonical, the decoded size and the size overhead, sniffs magic bytes to name the actual file type, splits a JWT into header, payload and claims with their registered names, unwraps a data: URI, recognises PEM armour and shows a hex dump of the first bytes so you can see what you are dealing with.

Encoder and decoder capabilities

  • Standard and URL-safe alphabets with padding control
  • MIME line wrapping at 64 or 76 characters with CRLF
  • UTF-8, Latin-1 and hex input modes
  • Exact size overhead and character-count reporting
  • Canonical trailing-bit validation on decode
  • Automatic standard versus base64url detection
  • Magic-byte identification of PNG, JPEG, GIF, ZIP, PDF and more
  • JWT header, payload and signature inspection with claim labels
  • data: URI and PEM block recognition
  • Hex dump preview and verified encode-decode round trip

How to encode and decode Base64

  1. 1Choose the tab: encode or decodeThe tab is mirrored into the URL, so /encoders-decoders/base64/#decode opens directly on decoding and can be shared as a link.
  2. 2Pick the alphabet and paddingStandard for MIME, email and data URIs; URL-safe for query parameters, path segments and JWT segments, where + and / must not appear. Padding is required for the standard alphabet and conventionally absent for base64url.
  3. 3Paste the text or the encoded stringFiles can be dropped onto the input pane; a file is read locally and encoded from its bytes, so binary content works without a text round trip.
  4. 4Read the inspection panelFor a decoded value, the panel states what it found: image or archive type, JWT claims, data URI media type, PEM label, whether it is text, and whether re-encoding reproduces the input byte for byte.

The variants, in one table

Alphabets, padding and line handling for each Base64 flavour named in the options.
VariantAlphabet tailPaddingLine rulesWhere you meet it
Standard (RFC 4648 §4)+ and /Required =Unfolded by defaultJSON fields, data URIs, email attachments.
base64url (§5)- and _Usually omittedNever wrappedJWT segments, URL parameters, Content-ID strings.
MIME (§3.5)+ and /RequiredWrapped at 76 with CRLFPEM armour, multipart bodies.
PEMstandardRequiredWrapped at 64Certificates and keys between BEGIN and END lines.

A string that decodes successfully in one variant can fail or produce different bytes in another, which is why the decoder reports the variant it settled on rather than accepting anything that looks like base64.

Frequently asked questions

Is Base64 encoding encryption?

No, and treating it as such is a recurring security mistake. Base64 is a reversible binary-to-text encoding with no key: any decoder, including this one, recovers the original bytes. It exists to move bytes through a channel that can only carry text. For confidentiality you need an actual cipher — see the Base64 guide.

Why does my JWT have no = signs?

JWTs use base64url (RFC 7515 §2), which replaces + with - and / with _ and strips padding, because the segments appear inside a URL-safe compact serialisation. Adding padding back changes the signature input, so never re-pad a segment before verifying.

Why does btoa() throw on my text?

Because btoa and atob accept only code points in the Latin-1 range, and characters above U+00FF raise InvalidCharacterError. The portable route is TextEncoder to bytes, then base64, which is what this tool does — no try/catch gymnastics required.

What is a non-canonical encoding?

When the final partial group has leftover bits that are not zero, several different inputs map to the same output. Zm9 and Zm5 both decode toward the same truncated byte pattern. If a system compares decoded values after re-encoding, two different secrets can appear equal; the decoder flags this explicitly.

How much bigger is Base64 than the original?

Always four characters per three bytes, so 33.3 percent overhead before padding, which adds up to two more characters. The panel reports the exact figure for your input, including where line wrapping adds further bytes.

Can I decode a binary file, like an image?

Yes. The decoder identifies the type from magic bytes and shows a hex dump, but it will not render the binary as text. If you need the file itself, a data URI can be opened directly, and the panel says when the payload is a data URI.

What does this tell me that atob() does not?

It chooses the alphabet from the characters present, so a base64url value containing "-" or "_" is decoded instead of throwing; unpacks the three JWS segments and prints header and claims; recognises a data: URI or a PEM block and names the payload from its magic bytes; applies the canonical trailing-bit rule from RFC 4648 §3.5 that most decoders skip; and separates the MIME conveniences — line wrapping, CRLF, ignored non-alphabet characters — from the encoding itself. That last point is the security-relevant one: two texts can decode to the same bytes, so a filter that inspects the decoded value is not looking at what a strict decoder will accept.