Tech News, Tech & Coding · Free Online Tools

IT Question Answer
Tools
How to Decode a JWT Token and What Each Part Means

How to Decode a JWT Token and What Each Part Means

Developer ToolsBy Muhammad Fareed3 min read
jwtauthenticationsecuritydeveloper-tools

A JSON Web Token (JWT) is a compact string that apps use to prove who you are. It looks like random text, but you can read it easily once you know its structure. Here is how to decode a JWT, what the parts mean and what decoding does not tell you.

The three parts of a JWT

A JWT has three sections separated by dots:

xxxxx.yyyyy.zzzzz
header.payload.signature
  • Header: the token type and signing algorithm, such as {"alg": "HS256", "typ": "JWT"}.
  • Payload: the claims, which are statements about the user and the token.
  • Signature: a value created with a secret or private key so the server can detect tampering.

How decoding works

The header and payload are JSON text encoded with Base64URL. Anyone can decode them, because encoding is not encryption. A tool such as the JWT Decoder splits the token, decodes each part and shows the readable JSON.

// JavaScript (browser)
const payload = JSON.parse(atob(token.split(".")[1].replace(/-/g, "+").replace(/_/g, "/")));

Common claims in the payload

ClaimMeaning
issIssuer: who created the token
subSubject: usually the user ID
audAudience: who the token is for
expExpiration time as a Unix timestamp
iatIssued-at time
nbfNot valid before this time

Applications can add custom claims such as roles or permissions.

Decoding is not verifying

Decoding only reveals what the token says. It does not prove the token is genuine. A server must verify the signature with the right key, and also check exp, iss and aud. Never trust a payload just because you can read it.

Security tips

  • Do not store sensitive data, such as passwords, in a JWT payload, since anyone with the token can read it.
  • Use short expiry times and refresh tokens where needed.
  • Always verify on the server and reject the none algorithm.
  • Send tokens only over HTTPS and protect them from script access when possible.
  • Avoid pasting real production tokens into online tools.

Where JWTs are used

  • Login sessions: a server issues a token after sign-in and the client sends it with each request.
  • APIs: services use tokens to check who is calling and what they may do.
  • Single sign-on: identity providers issue tokens that other apps accept.

Decoding a token during development helps you check which claims the server received and when the token expires.

Key takeaways

  • A JWT is header.payload.signature, and the first two parts are only Base64URL-encoded.
  • Decoding shows the claims, but only signature verification proves a token is genuine.
  • Keep sensitive data out of tokens and use short expiry times.

Frequently asked questions

Is a JWT encrypted?

A standard signed JWT is not encrypted. Its content is only encoded, so anyone holding the token can read it. Encrypted tokens (JWE) exist but are different.

What does an expired JWT mean?

The current time is past the exp claim. The server should reject it, and the client usually needs to sign in again or use a refresh token.

Can I change a JWT payload myself?

You can edit the text, but the signature will no longer match, so a server that verifies signatures will reject the token.

Try JWT Token Decoder free

Advertisement

Related posts