What Is a JWT? How JSON Web Tokens Work and How to Decode One

By 4 min read

A JWT (JSON Web Token) is a compact, URL-safe string that carries a small JSON object of claims, such as who a user is and when the token expires, plus a signature that lets a server check that nobody has changed it. It has three parts separated by dots: header, payload and signature. The header and payload are only encoded, not encrypted, so anyone who has the token can read them with a JWT decoder. JWTs are defined in RFC 7519, published in May 2015, and are widely used for logins and API access.

What a JWT looks like

Here is a complete token, signed with a demo secret:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzQyIiwibmFtZSI6IlNhcmEgTWFsaWsiLCJyb2xlIjoiZWRpdG9yIiwiaWF0IjoxNzk1NTk3MjAwLCJleHAiOjE3OTU2MDA4MDB9.efoFoxJgAZ6J3baa_nMXw1X9sxDXDLuJn0QfmmgfUpE

The two dots split it into its three parts. The header and payload both start with "eyJ". That is what {" followed by a letter becomes after encoding, so "eyJ" at the start of a string is a good sign of encoded JSON.

Part 1: the header

The first part decodes to:

{"alg":"HS256","typ":"JWT"}

"typ" says this is a JWT, and "alg" names the signing algorithm. Common values are:

  • HS256: HMAC with SHA-256. The same shared secret signs and checks the token.
  • RS256: an RSA signature with SHA-256. A private key signs and a public key checks.
  • ES256: an elliptic curve (ECDSA) signature with SHA-256, with shorter keys than RSA.
  • none: no signature at all. A server should never accept these for anything that matters.

Part 2: the payload and its claims

The second part holds the claims:

{"sub":"user_42","name":"Sara Malik","role":"editor","iat":1795597200,"exp":1795600800}

RFC 7519 registers seven short claim names. All are optional, but most tokens use several:

Claim Name Meaning
iss Issuer Who created the token
sub Subject Who the token is about, often a user ID
aud Audience Who the token is meant for
exp Expiration time When it stops being valid
nbf Not before When it starts being valid
iat Issued at When it was created
jti JWT ID A unique ID, useful for blocking reuse

Anything else, like "name" and "role" above, is a claim the application defines for itself.

The times are not dates you can read at a glance. They are NumericDate values: the number of seconds since 1 January 1970 UTC, the same count as a Unix timestamp. Paste them into the epoch converter or the Unix timestamp converter:

  • iat 1795597200 is 25 November 2026, 09:00:00 UTC.
  • exp 1795600800 is 25 November 2026, 10:00:00 UTC.

The difference is 1795600800 - 1795597200 = 3,600 seconds, so this token is valid for exactly one hour.

Part 3: the signature

For HS256, the server takes the first two parts exactly as they appear, joined by a dot, and runs them through HMAC-SHA256 with its secret key. The result, Base64URL encoded, is the third part. When the token comes back, the server repeats the calculation. If anyone changed even one character of the header or payload, for example "editor" to "admin", the signatures no longer match and the token is rejected.

The signature proves the token is genuine and unchanged. It does not hide anything.

Base64URL, not quite Base64

Each part uses Base64URL, a variant of Base64 that is safe in web addresses. It uses - instead of +, _ instead of /, and drops the = padding at the end.

That matters if you try to read a part with an ordinary decoder. The Base64 decoder reads standard Base64, so it decodes a JWT part only when that part happens to contain no - or _ characters. In the example, the header and payload decode cleanly. The signature contains an _ and is raw binary anyway, so it does not. The JWT decoder handles Base64URL directly.

How to decode a JWT

  1. Copy the token. In a web app you can often find it in your browser's developer tools, in the Network tab, after "Bearer" in a request's Authorization header.
  2. Paste it into the JWT decoder. It splits the token at the dots and decodes the header and payload in your browser.
  3. Read the header and payload, shown as indented JSON. The tool reports the signature as present but not verified.
  4. Convert iat, exp and nbf with the epoch converter to see when the token was issued and when it expires.

If you have copied a decoded payload somewhere else and want it laid out neatly, the JSON formatter indents it and checks that it is valid JSON.

The decoder expects the usual three-part signed token. An encrypted JWT (a JWE) has five parts and cannot be read without the key, so the decoder rejects it.

Decoding is not verifying

Anyone can write a payload that says "role":"admin", encode it and attach a made-up signature. A decoder will show that payload without complaint, because decoding only reads. Only the server, holding the secret or the public key, can verify a token. Proper verification also checks that exp has not passed, that nbf has been reached, that iss and aud are the expected values, and that alg is the algorithm the server expects.

Keep tokens safe

  • Treat a valid JWT like a password. Whoever holds it can act as the user until it expires. Do not paste live production tokens into tools you do not trust.
  • Never put secrets in the payload. Passwords, card numbers and private data can be read by anyone who sees the token.
  • Keep expiry short. A token that lasts an hour, like the example, does less harm if it leaks than one that lasts a month.

Questions and answers

Is a JWT encrypted?

Usually not. A normal JWT is signed, so its header and payload can be read by anyone who has it. Only an encrypted JWT (JWE), which has five parts instead of three, hides its contents.

Can I decode a JWT without the secret key?

Yes. The header and payload are only Base64URL encoded, so a JWT decoder can read them without any key. You need the secret or public key only to verify the signature.

What does exp mean in a JWT?

exp is the expiration time, in seconds since 1 January 1970 UTC. After that moment the token must not be accepted. Paste the number into an epoch converter to see the date and time.

Related guides

More from the blog