opyebJWTlab

JWT structure and Base64URL: reading the three parts correctly

Basics · 6 min read

In one line: What the header, payload and signature parts carry, how Base64URL differs from Base64, and where people go wrong when reading a token.

A JWT is a single string split by two dots. From the left they are the header, the payload and the signature, and each part is JSON encoded as Base64URL. Knowing that shape lets you narrow down a "the token is broken" problem in seconds.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
.eyJzdWIiOiJ1c2VyLTEwNDIiLCJleHAiOjE4OTM0NTYwMDB9
.QgmkLbZgfYEnWd1q...

What each part holds

PartContentsRequired
headerMetadata such as alg (signature algorithm), typ and kid (key ID)yes
payloadClaims such as iss, sub, aud and exp. A JWT does not encrypt these valuesyes
signatureA signature or HMAC tag over the header.payload bytesdepends on the algorithm

Anyone can decode the payload. A token is signed, not encrypted, so passwords, national ID numbers and internal hostnames do not belong in it. When confidentiality matters, use JWE or keep only an identifier in the token and look the details up on the server.

How Base64URL differs from Base64

JWT uses Base64URL so the text can travel in URLs, headers and cookies unchanged. Standard Base64 uses + and /; Base64URL uses - and _, and the trailing = padding is omitted. That is why a token's length may not be a multiple of four and why a decoder must restore the padding before decoding.

  • Missing padding is not a broken token: add zero to two = characters depending on the length modulo four.
  • Stray spaces or line breaks break decoding. Strip the line breaks that copy and paste introduces.
  • A Bearer prefix is HTTP header syntax, not part of the token.

Common mistakes

The most common is verifying without checking alg. The header is attacker-controlled, so a verifier must decide in advance which algorithms it accepts and reject anything else. The second is ignoring kid. With several keys in play, skipping the key ID means trying the wrong key or a key that belongs to another issuer.

Decoding and signature checks run right here in your browser. The token you paste is not stored.

Open the JWTlab decoder

Frequently asked questions

If I decode a token, is the personal data visible?

Yes. The payload is signed but not encrypted, so anyone can Base64URL-decode and read it. It also tends to linger in browser dev tools, proxy logs and error trackers, which is why personal data and secrets should not go into a token.

What changes if I use a JWT instead of a session cookie?

A JWT lets you avoid server-side state, but it is hard to revoke after issue. To reflect logout or a permission change immediately you need short expiry plus refresh tokens, or a server-side revocation list.

Sources

Read next