Matching a Base64url field’s padding policy
Base64url output can be written with or without trailing equals signs. A field that documents a padding policy decides which one you produce, and both spellings carry the same text.
What Base64url changes in Base64
Base64url is the variant defined in section 5 of RFC 4648 for use in URLs and file names. It replaces two characters of the standard alphabet. Plus becomes minus and slash becomes underscore, because plus and slash have special meanings in web addresses. Everything else about the encoding is the same: three bytes become four characters, and the final group of a message may be short. The padding rules are where practice differs most. The standard allows a specification to omit the equals signs, and many Base64url users do omit them, since an equals sign inside a query string or cookie needs escaping or can be mistaken for a separator.
Encoding fo with padding
The text fo is two bytes, 66 and 6F in hexadecimal, or 01100110 and 01101111 in binary. Cut into six-bit pieces, those sixteen bits become 011001, 100110, 1111 followed by two zero bits. In decimal those are 25, 38 and 60, which map to Z, m and 8. The group is one character short, so the padded output adds one equals sign and reads Zm8=. The first case selects padding on and returns that value. Nothing about this string is specific to the URL-safe alphabet, since none of the characters that differ, minus and underscore, happened to be needed for these particular bytes.
Encoding fo without padding
The second case turns padding off and returns Zm8. The three characters are identical to the first three characters of the padded form, and the only change is the missing equals sign. The text that was encoded is the same two bytes. The padding selector affects the end of the output string and nothing else, so it cannot change how the decoder will interpret the earlier characters. If a system you send data to documents unpadded output, the second form is the one to produce. If it documents padded output, or says nothing, the first is the safer choice, since decoders that need no padding generally still accept it.
Decoding the unpadded form
The third case sets padding to false and decodes Zm8, returning fo. The decoder works out the length of the final group from the number of characters, three, restores the missing equals sign internally and then decodes as usual. A group of two characters stands for one byte, three characters stand for two bytes, and four characters stand for three. One character alone is impossible because it holds only six bits. This is how formats that omit padding can still be decoded without ambiguity, and why a decoder can accept the unpadded form while a stricter standard decoder insists on the signs.
Where specifications fix a policy
Several well-known formats choose a policy and state it. JSON Web Signature in RFC 7515 uses Base64url without padding for the parts of a signed token, so the three dot-separated sections never end with an equals sign. Other APIs return padded values, and some filenames or identifiers use unpadded ones to stay short. When you build a request or compare a token, read the format description for the words padding and omit. An unpadded token that gains an equals sign may fail signature verification or be rejected by a strict parser, and a padded value stripped by a careless script may fail in a system that expects the signs.
Keeping the policy with a saved example
A saved example of an encoded value is only reproducible if the padding choice is recorded with it. Another person who encodes the same text with the opposite setting will get a different string and may suspect that the text differs. Writing the setting next to the sample, for example the text fo, Base64url, padding on, and the result Zm8=, avoids that. The same advice applies to test fixtures in code: a test that compares encoded strings should state its policy, or compare decoded values instead, which are equal regardless of the padding.
A successful local decode proves little about the receiver
This tool accepts the unpadded form, but a receiving service may not. Some servers insist on padding, others reject it, and some accept either. A local decode establishes that the text fits this decoder and nothing more. Before sending a value, check the format requirements of the receiver. When the receiver offers no documentation, send a small test value and look at the response. The best approach for an unknown receiver is to start from the encoding that a client library for that service produces. Another useful habit is to keep both forms of a sample, padded and unpadded, in your test data, so that you notice at once if a receiver accepts only one. Errors in this area tend to appear late, when a value happens to have a short final group, so testing with texts of one, two and three bytes catches the three possible shapes of the last group.
Another pair of bytes
The text hi is two bytes, 68 and 69. The sixteen bits 01101000 01101001 give the six-bit pieces 011010, 000110, 1001 and 00, so 26, 6 and 36, which map to a, G and k. The padded form is aGk= and the unpadded form is aGk. Bytes that fill a full group need no choice at all: the three-byte text foo is Zm9v with or without the padding setting. Padding only affects messages whose length is not a multiple of three bytes, which is why a policy question can go unnoticed until a value happens to have one or two leftover bytes.
Related checks when a value looks wrong
If a value fails to decode, look at the alphabet first. Characters plus and slash indicate standard Base64, and minus and underscore indicate Base64url. A mix of both is a sign that the value was edited or built by joining two sources. Then count characters: a remainder of one when dividing the length by four means data was lost, not padding. Finally compare with a trusted encoder using a known text. These checks are quick and separate the common problems: wrong alphabet, a missing or extra padding sign and a damaged value. A value that mixes padded and unpadded pieces, for instance two encoded parts joined by a dot with an equals sign at the end of only one, usually shows that the parts came from different tools and should be produced under one policy.
Reproduce the checks
Keep padding
Open the Base64Url Encoder Decoder and enter:
- Calculation mode
encode- Include Base64 padding
true- Text or encoded input
fo
Expected output:
Text
Zm8=The output includes one terminal padding character.
Omit padding
Open the Base64Url Encoder Decoder and enter:
- Calculation mode
encode- Include Base64 padding
false- Text or encoded input
fo
Expected output:
Text
Zm8The underlying source text has not changed.
Decode the unpadded form
Open the Base64Url Encoder Decoder and enter:
- Calculation mode
decode- Include Base64 padding
false- Text or encoded input
Zm8
Expected output:
Text
foThis decoder restores the final group internally.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08