What is a JSON Web Token (JWT)?
A JWT is a short piece of text that carries claims, such as who a user is and when their sign-in ends, from one system to another. It has three parts joined by dots: header.payload.signature. The header says how the token is signed, the payload holds the claims, and the signature lets the receiver check that nobody changed them.
The header and payload are JSON written in base64url, a version of Base64 that uses - and _ and leaves out the = padding, so the token is safe in web addresses. Base64url hides nothing: the claims are readable by anyone who has the token. Only an encrypted JWT (JWE), which has five parts, keeps them secret.
Source RFC 7519 · JSON Web Token (JWT) ↗RFC 7515 · JSON Web Signature (JWS) ↗RFC 4648 · The Base16, Base32, and Base64 Data Encodings ↗RFC 7516 · JSON Web Encryption (JWE) ↗
How to decode a JWT
Here it is with your numbers:
- Split the token at its 2 dots: a header of 36 characters, a payload of 96 and a signature of 43.
- Base64url-decode the header and read it as JSON: {"alg":"HS256","typ":"JWT"}.
- Decode the payload the same way. It holds 4 claims: sub, name, iat, exp.
- The exp claim, 2,082,758,400, counts seconds from January 1, 1970 (UTC), which makes it Jan 1, 2036, 12:00:00 AM UTC.
It means anyone can read these claims. Only checking the HS256 signature with the issuer’s key shows they are genuine.
Decoding is not verifying. To trust a token, the app that receives it checks the signature with the issuer’s key and the algorithm it expects, then checks the dates. Never paste a live token into a site that sends it to a server: whoever has it can use it until it expires.
JWT date claims: iat, nbf and exp
| Claim | Means |
|---|---|
| iat | Issued at: when the token was made |
| nbf | Not before: the first second it can be used |
| exp | Expiration time |
All three are seconds since 00:00:00 UTC on January 1, 1970, the same count as a Unix timestamp, and all three are optional. The standard lets apps allow a little leeway, usually no more than a few minutes, for clocks that don’t agree.
JWT examples
| Example | Algorithm |
|---|---|
| Sign-in token (HS256) | HS256 |
| RFC 7519 example (HS256) | HS256 |
| RFC 7519 unsecured example | none |
| Not valid yet (nbf) | HS256 |
| No expiry (no exp) | HS256 |
The two RFC 7519 tokens are copied exactly from the standard; the others were made for this page.
FAQs
What is a JWT decoder?
A tool that turns the two readable parts of a JSON Web Token, the header and the payload, back into JSON. Each part is base64url-encoded JSON, so decoding is just reversing that encoding. It doesn’t check the signature.
Can I decode a JWT without the secret key?
Yes. A signed JWT isn’t encrypted: its header and payload are only base64url-encoded, so anyone can read them. The key is needed to check the signature, or to open an encrypted JWT (JWE, 5 parts instead of 3).
How can I check if a JWT is expired?
Decode the payload and read the exp claim: the number of seconds since January 1, 1970 (UTC). The token is expired from that second on; it must be refused unless the current time is before exp. Some apps allow a few minutes of leeway for clock differences.
What does it mean when a JWT expires?
After its exp time, the app that receives the token must not accept it, so you have to get a new one, usually by signing in again. Nothing in the token itself changes.
Can a JWT never expire?
Yes. The exp claim is optional, so a token without one has no expiry date of its own. The app checking it can still refuse it for other reasons.
What is a JWT token for?
It is a compact, URL-safe way to pass claims between two parties, such as who you are and when your sign-in ends, small enough for an HTTP Authorization header or a web address.
Sources
- RFC 7519: JSON Web Token (JWT)
- RFC 7515: JSON Web Signature (JWS)
- RFC 4648: The Base16, Base32, and Base64 Data Encodings
- RFC 7516: JSON Web Encryption (JWE)