Why JWTs use URL-safe Base64 instead of standard Base64
By TechCompare · Updated · How we check
Use URL-safe Base64 for anything that appears in a URL: JWT tokens, OAuth state parameters, verification tokens in emails, and data URIs embedded in SVG. Standard Base64 is for everything else: JSON payloads, MIME attachments, and storage.
Standard Base64 uses + and / in its 64-character alphabet. Those characters have special meaning in URLs (+ is a space in query strings, / is a path separator), so putting standard Base64 in a URL requires percent-encoding. URL-safe Base64 (RFC 4648 §5) replaces + with - and / with _, making the output safe to drop directly into a URL path or query string without any encoding.
How this is calculated
JWT tokens use URL-safe Base64 for all three segments (header, payload, signature). JOSE requires unpadded Base64url for these segments. That is a token-format rule, not a restriction of the Authorization header: RFC 6750 permits +, /, and trailing = in Bearer credentials without percent-encoding.
URL components have separate escaping rules. URL-safe Base64 also commonly omits the = padding characters, since the encoded length can be inferred from the string length.
JavaScript's btoa() produces standard Base64. To get URL-safe, replace + with -, / with _, and strip trailing =. Most JWT libraries handle this automatically, but if you're hand-rolling token generation, this is a common mistake.
Verdict
Use URL-safe Base64 for anything that goes in a URL and standard Base64 for the rest. JavaScript's btoa() still emits standard output, so swap the characters manually or use a library.
More Encoding scenarios
Related guides
Frequently asked questions
What's the difference between standard Base64 and URL-safe Base64?
Why do JWT tokens use URL-safe Base64 instead of standard Base64?
How do I convert btoa() output to URL-safe Base64 in JavaScript?
Related tools
JSON Formatter
Validate, format, and minify JSON. Browse it as a tree, run JSONPath queries, compare two documents, or validate against a JSON Schema.
Use toolUnix Timestamp
Convert between Unix timestamps and human-readable dates.
Use toolCron Generator
Visually build standard 5-part cron expressions or translate them into readable schedules.
Use tool