Why a second Base64 alphabet exists

Standard Base64 uses plus and slash, and both cause trouble in URLs and file names. A slash separates path segments, and a plus can be read as a space in form-encoded query strings. RFC 4648 therefore defines a URL-safe variant that uses minus and underscore in their place. Everything else matches standard Base64: three bytes become four characters, and the other 62 characters are the same. This page encodes text with that alphabet and decodes it again, with an explicit choice about padding. It is the form used in JSON Web Tokens, many API identifiers and some cloud storage object names. The alphabet has 64 symbols plus the padding character, and the URL-safe table simply swaps the last two symbols, index 62 and index 63. Because the change is so small, a converter between the two forms only needs to swap those characters and adjust the padding.

Spotting the difference in practice

Most text encodes the same in both forms. The difference appears only when a 6-bit value is 62 or 63. The text >>> encodes to Pj4+ in standard Base64 and to Pj4- here, and the text ??? encodes to Pz8/ in standard form and Pz8_ here. These strings are only three characters long in the input, yet they show both substitutions. If an encoded token contains minus or underscore, it is probably URL-safe. If it contains plus or slash, it is standard Base64. Using the wrong decoder on a token with one of these characters is a common cause of an invalid character error.

Padding on or off

The default setting is no padding, so the text f encodes to Zg. With padding on, the same text becomes Zg==. Padding carries no data; it only brings the length to a multiple of four. The equals sign is also a reserved character in URLs and query strings, which is why many specifications drop it. JSON Web Signature, for instance, requires URL-safe Base64 without padding. The text é gives w6k without padding and w6k= with it. When decoding, this page accepts both padded and unpadded forms as long as they are canonical, so you can paste a token as you found it. Length gives a hint about the content: an unpadded string of 2 mod 4 characters carries one trailing byte, and 3 mod 4 carries two. A string that is 1 mod 4 characters long can never be valid, which is a quick test for a truncated token before you decode anything at all.

Encoding step by step

The page converts the text to UTF-8 bytes, groups them in threes, splits each group into four 6-bit values and maps each to the URL-safe alphabet. Then it applies your padding choice. The text fo gives Zm8 without padding and Zm8= with it. The text foo gives Zm9v either way, because three bytes need no padding. A JSON header such as {"alg":"HS256","typ":"JWT"} encodes to eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9, the familiar start of many tokens. Decoding that string with this page returns the JSON text, which is a quick way to inspect what a token header declares.

Inspecting a token safely

A signed token has three parts separated by periods. The first two are URL-safe Base64 of JSON text, and the third is a signature. Pasting the first or second part into the decode box shows the claims, such as the issuer or the expiry time. Decoding is not verification. Anyone can write any claim into a token, and only a signature check with the right key shows that the contents are genuine. The signature part is binary and will not decode as text. Avoid pasting live production tokens into any web tool if they grant access to real accounts.

Base64url is not percent encoding

URL-safe Base64 and percent encoding solve related problems in different ways. Percent encoding keeps the original characters and replaces each unsafe one with a percent sign and two hex digits, so a space becomes %20. Base64url re-encodes the whole payload into a restricted alphabet, which makes it longer but safe in paths and parameters without further escaping. Applying percent encoding to a standard Base64 string works too, since plus becomes %2B and slash becomes %2F, but the result is longer and harder to read. Use the URL encoder page when you need component escaping.

Strict decoding

On decode, the page accepts only letters, digits, minus, underscore and up to two trailing equals signs. It rejects plus and slash, whitespace, wrong padding and nonzero leftover bits in the last character. The string Zg decodes to f, while Zh is rejected because the last six bits are not zero. A length that leaves one extra character, such as five characters in an unpadded string, is also invalid, because a single leftover character cannot represent a whole byte. Strict rules catch copy errors early, such as a token cut off by a chat client or a line wrapped in an email.

Choosing the right option

Use no padding when a specification asks for it, which includes JSON Web Tokens and many URL parameters. Use padding when a legacy decoder or protocol expects the length to be a multiple of four. If you are unsure, test the receiving system with a short example, such as f, which should arrive as Zg or Zg==. Do not mix conventions within one system, since a comparison of two strings that differ only in trailing equals signs would fail even though they hold the same bytes. Store the padding choice in your documentation so that later changes do not break existing links. When identifiers are generated by code and shown in addresses, an unpadded URL-safe string is also shorter and avoids characters that need escaping, which makes shared links tidier. For a stored value that other programs will read, say in a configuration file, padded output is the safer default because the strictest decoders accept it.

Binary data that Base64URL decoding cannot return

The page handles text up to 1 MiB of UTF-8, and the output is text only. Decoding fails for binary data that is not valid UTF-8, for malformed padding and for nonzero pad bits. Base64url is neither encryption nor compression, and it makes data longer by about one third. The page does not check what the decoded text means, whether a token is valid or whether a signature matches. Treat decoded content as untrusted input, and do not rely on this page for authentication or security decisions.