Skip to content

Base64url encoder and decoder

Convert text or bytes to and from Base64url, the URL-safe Base64 that JWT headers, payloads and signatures use.

Runs in your browser. Nothing you paste is sent to us.

Input

A sample is filled in. Text is encoded as UTF-8.

Result

Base64url
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InNhbXBsZS1hY21lLXJzMjU2In0
Input
53 bytes
Output
71 characters

How to use it

  1. Choose encode or decode.
  2. Type or paste the text, hex bytes or Base64url.
  3. Copy the result. Decoded JSON is shown formatted.
  4. Use the result as input to go the other way.

What to know

Base64url is Base64 with - and _ in place of + and /, so it is safe in URLs and file names. JWTs leave out the = padding.

Each part of a JWT is Base64url. Paste the first or second part of a token here to read its header or claims.

PKCE code challenges and many OAuth values use Base64url too.

What Base64url is

Base64url is a variant of Base64 defined in RFC 4648, section 5. It turns any bytes into text made of 64 safe characters, like Base64, but swaps the two characters that cause trouble in URLs and file names: + becomes - and / becomes _.

JWTs, JWS and JWE all use Base64url, and they leave out the = padding (RFC 7515, section 2). So do PKCE code challenges and many other OAuth values. Whenever you see a long string of letters, digits, dashes and underscores in an auth flow, it is probably Base64url.

How the encoding works

The input bytes are taken three at a time, 24 bits. Those bits are split into four groups of 6 bits, and each group picks one character from the alphabet. Three bytes always become four characters.

ValuesBase64Base64url
0 to 25A to ZA to Z
26 to 51a to za to z
52 to 610 to 90 to 9
62+-
63/_
Padding=Usually left out

When the input length is not a multiple of three, the last group is short. Standard Base64 fills it with = signs; Base64url in JWTs drops them, and decoders work out the missing length.

A JWT header, encoded (no + or / here, so both forms match)
text      {"alg":"RS256"}
base64    eyJhbGciOiJSUzI1NiJ9
base64url eyJhbGciOiJSUzI1NiJ9

What this tool does

  • Encodes text as UTF-8, or raw bytes given as hex, into Base64url.
  • Decodes Base64url back to text, and always to hex as well.
  • Shows decoded JSON formatted, which is handy for JWT parts.
  • Adds or leaves out the = padding, as you choose.
  • Tells you when input uses + and /, which means it is standard Base64, and decodes it anyway.
  • Names the bad character or impossible length when decoding fails.

Everything runs in your browser. Use the button to feed the result back as input and go the other way.

Step by step

  1. Choose Encode or Decode.
  2. For encoding, choose whether the input is text or hex bytes, then type or paste it.
  3. For decoding, paste the Base64url string; spaces and line breaks are ignored.
  4. Copy the result.

Reading JWT parts by hand

Each part of a JWT between the dots is Base64url. Paste the first part to read the header, or the second to read the claims; the tool formats the JSON. The third part is the signature: it decodes to bytes, not text, so the tool shows it as hex.

For everyday work the JWT decoder does all three at once. This tool is useful when you want to see one part alone, edit it, and encode it again to understand how a token is built.

JWTs come in two other forms you may meet. An unsecured JWT with alg: none has an empty third part, so it ends with a dot. A JWS with a detached payload has an empty second part, so two dots sit next to each other. Both still use Base64url for the parts that are present.

Where Base64url shows up in OAuth and Keycloak

  • JWT access tokens and ID tokens: every part.
  • PKCE: the code_challenge is the Base64url SHA-256 hash of the code_verifier, without padding (RFC 7636).
  • JWKs: key numbers such as n, e, x, y and k are Base64url.
  • Thumbprints: x5t, x5t#S256 and RFC 7638 key thumbprints are Base64url.

Use cases

Debugging a PKCE mismatch

If an authorization server says the code verifier does not match, check that the challenge was made with Base64url, not Base64, and without padding. A +, / or = in the challenge is the giveaway. The PKCE generator makes a correct pair.

Building test tokens step by step

Encode a header and a payload here to see the signing input of a JWT form in front of you. Then sign it with the JWT encoder.

Inspecting key material

Decode a JWK’s n or x to hex to compare it with a key printed by OpenSSL.

Common errors

MessageCause
“…” is not a Base64url characterA quote, space inside the value, or other stray character from copying
The length is not possibleOne character too many or too few, often a cut-off copy
Uses + and /, so it is standard Base64The value was encoded with plain Base64
The bytes are not UTF-8 textBinary data such as a signature or a key; read the hex

Padding and length, worked out

Because Base64url in JWTs has no padding, a decoder must work out how many bytes the last group holds from the length alone. The rule is simple: take the length modulo 4.

Length mod 4Last group holdsPadding a decoder adds
0A full 3 bytesNone
21 byte==
32 bytes=
1ImpossibleThe value is damaged

A length that leaves 1 after dividing by 4 can never come from a correct encoder. It almost always means one character was lost or added when the value was copied. This tool reports it as an impossible length instead of guessing.

Base64url in code

Most languages have a Base64url function built in or in a standard library. Using it is safer than replacing characters by hand.

Encoding without padding in three languages
// JavaScript (browser and Node.js)
btoa(text).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
Buffer.from(bytes).toString('base64url');   // Node.js only

# Python
base64.urlsafe_b64encode(data).rstrip(b'=')

// Java
Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);

Note that btoa in browsers accepts only characters up to U+00FF. Text with other characters must be turned into UTF-8 bytes first, which this tool does for you.

Checking a JWT part by hand

Decoding one part at a time is a good way to understand why a token fails to parse.

  1. Split the token at the dots and paste the first part. You should see JSON with alg.
  2. Paste the second part. You should see the claims as JSON.
  3. Paste the third part. You should see hex bytes; their count tells you the signature size, such as 256 bytes for RS256 with a 2048-bit key.
  4. If any part fails, the token was damaged where that part sits.

The same check helps with JWK members. A modulus n that decodes to 256 bytes belongs to a 2048-bit RSA key; an EC x that decodes to 32 bytes belongs to a P-256 key.

Notes and limits

Base64url is an encoding, not encryption or compression. Anyone can decode it, and the output is about a third larger than the input.

Some systems accept Base64url with padding, others reject it. JWTs must not have padding; PKCE challenges must not either. When unsure, leave it out.

This page reads only what you type or paste. Nothing is sent to us.

When you compare two Base64url strings, compare the decoded bytes rather than the text. Padding, or its absence, changes the text but not the bytes, and some encoders differ in how they handle the unused bits at the end. Decoding both here and comparing the hex settles the question.

Base64url output is also case-sensitive. abc and ABC decode to different bytes, so tools that lower-case identifiers, such as some URL routers or databases with case-insensitive collation, can corrupt Base64url values silently.

Best practices

  • Use a library function made for Base64url rather than replacing characters by hand.
  • Decide on padding once and be consistent between encoder and decoder.
  • Encode text as UTF-8 before Base64url so non-English characters survive.
Questions

Frequently asked questions

What is the difference between Base64 and Base64url?

Two characters and the padding. Base64 uses `+` and `/` and pads with `=`; Base64url uses `-` and `_` and, in JWTs, has no padding.

Why does decoding fail?

The text has a character outside the alphabet, or a length that no Base64 can have. The message names the problem; copying the value again from the source usually fixes it.

Does a JWT use padding?

No. RFC 7515 says the `=` padding is left out in JWS, and JWTs follow that. A decoder adds the missing padding back before decoding.

Can I decode a JWT signature to text?

No. The signature is binary bytes, not text. The tool shows it as hex instead.

Is Base64url encryption?

No. It is a reversible encoding that anyone can decode. Never rely on it to hide anything.

Why is my PKCE challenge rejected?

A common cause is encoding the hash with standard Base64 instead of Base64url, or leaving `=` padding on. The challenge must be Base64url without padding.

How do I convert Base64 to Base64url?

Replace `+` with `-` and `/` with `_`, and remove trailing `=`. Or decode it here and encode the result again.

Why does my decoder need padding added back?

Some Base64 decoders insist on input whose length is a multiple of 4. Base64url values from JWTs have no padding, so such decoders need one or two `=` signs added first. This tool adds them automatically.

Is Base64url safe to put in a URL without further encoding?

Yes, as long as it has no `=` padding. The alphabet uses only letters, digits, `-` and `_`, which need no percent-encoding in a URL.

Why does `btoa` fail on my text?

Browsers’ `btoa` accepts only characters up to U+00FF. Encode the text as UTF-8 bytes first, as this tool does, and then Base64url-encode the bytes.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.