What Is a JWT (JSON Web Token) and How Does It Work? Decoding, Signature and Security
Updated: November 6, 2026 · AracMerkezi
A JWT (JSON Web Token) is a compact token used to carry information between two parties. In web and mobile apps it is most often seen for authentication and authorization: when a user logs in the server produces a JWT, and the client sends this token in later requests. Instead of repeating the concept, this guide decodes a real sample token piece by piece, shows what the signature is for with a tampering test, and lists the traps developers fall into most often. The values in the example were produced and verified with Node.js; the key is for demonstration only.
Structure
A JWT is made of three parts separated by dots:
- Header: Contains the signing algorithm and the token type.
- Payload: Carries the data called “claims”: user ID, permissions, validity period and so on.
- Signature: Produced by signing the header and payload with a secret key.
The first two parts are JSON encoded with Base64URL; Base64URL is the Base64 variant that uses - and _ instead of + and / and drops the padding sign.
Example 1: Decoding a real token
The token below was produced with the key demo-secret using the HS256 algorithm:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0IiwibmFtZSI6IkF5c2UiLCJpYXQiOjE3OTM4NjkyMDAsImV4cCI6MTc5Mzg3MDEwMH0.m_uMOTgIoMv2FQIcVw7ejOIeuwv6-ZOrfEvIgDyBWcw
The header (eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9) decodes to {"alg":"HS256","typ":"JWT"}.
The payload decodes to {"sub":"1234","name":"Ayse","iat":1793869200,"exp":1793870100}. The time fields are Unix time (seconds since January 1, 1970): iat = 1793869200, that is November 5, 2026 09:00 UTC; exp = 1793870100, that is 09:15 UTC. The difference is 1793870100 − 1793869200 = 900 seconds = 15 minutes; the token is valid for 15 minutes. To convert a timestamp by hand, see the Unix timestamp guide and the Unix Timestamp Converter.
The signature is the last part: m_uMOTgI… is a 43-character Base64URL string that carries the HMAC-SHA256 digest of the first two parts.
Important claims
| Field | Meaning |
|---|---|
| iss | The issuer of the token |
| sub | Subject, usually the user ID |
| aud | Audience |
| exp | Expiration time (Unix time, seconds) |
| iat | Issued-at time |
| nbf | Not valid before this time |
Example 2: A tampering attempt
Let an attacker change the sub value in the payload from 1234 to 9999 and re-encode the token to Base64URL. The header and payload are now different; the server recomputes the signature with the same key, and the result does not match the signature the token carries. We ran this test and the signatures came out different. Someone who does not know the key cannot produce the right signature; that is the purpose of the signature. The signature does not hide the content; it only shows whether it has been changed.
Example 3: Time remaining
When the server receives the token at 09:10 UTC on November 5, 2026, the time remaining is: exp − now = 09:15 − 09:10 = 5 minutes; the token is valid. If it arrives at 09:16, exp has passed and the server should reject it. To tolerate small clock differences many libraries allow a margin of a few seconds; how many seconds that is varies from library to library.
A very common misunderstanding
A JWT is not encrypted, only signed. Anyone can decode the payload from Base64URL and read it. Do not put secrets such as passwords or credit card numbers in a token. Decoding a token does not mean verifying it; verification requires checking the signature with the key and looking at the exp value. For a similar distinction, see the encoding–encryption–hash table in the JSON, Base64 and URL encode guide; for the hash concept the What is a hash article is helpful.
Symmetric and asymmetric signatures
With symmetric algorithms such as HS256, the party that signs and the party that verifies know the same secret key. With asymmetric algorithms such as RS256, a private key signs the token and verification is done with a public key; this is practical in systems where many services must verify the token, because you do not give the verifiers the power to sign.
The verification flow: what should the server do?
When a token arrives with a request, the server follows these steps in order:
- It splits the token at the dots into three parts; if there are not three parts, it rejects it.
- It checks that the algorithm in the header is on the allowed list.
- It recomputes the signature from the first two parts with its own key and compares it with the one in the token. Doing the comparison with a constant-time function prevents timing attacks.
- It compares
expand, if present,nbfwith the current time. - It checks that
issandaudmatch what is expected; a token issued for another service must not get past this one.
If any step is skipped, the token is only “readable”, not “trustworthy”. The token in the example is 164 characters; since this size is carried in a header with every request, not putting unnecessary fields in the payload protects both speed and privacy.
Security tips
- Always verify the signature on the server side and fix the accepted algorithm (do not accept the
nonealgorithm). - Keep the validity period (exp) short and use a refresh token.
- Do not put the secret key in the code repository.
- Consider storing tokens in secure (HttpOnly, Secure) cookies.
- Do not paste real tokens from live systems into sites you do not know.
Common mistakes
- Putting secret information in the payload.
- Trusting a token only by decoding it, without verifying.
- Never checking the
expfield or keeping the lifetime days long. - Reading the algorithm from the header in the token and accepting it as is.
- Assuming a token becomes invalid by itself when the user logs out. A JWT holds no state on the server; early revocation needs an extra mechanism (short lifetime, a deny list, a version counter).
When a JWT, when a session cookie?
With a single application and a single group of servers, a classic session record kept on the server is easier for revocation and monitoring. A JWT has an advantage when identity information must be carried between several services without asking the server; the price is that revocation gets harder. The choice is made according to the application's needs. When deciding, ask these questions: Do I need to be able to log a user out instantly? How many different services will verify the token? In which environments (browser, mobile, server to server) will the token travel? The answers may not point to a single right option; in that case compare both approaches with a small trial.
To inspect the content of a token you can use the JWT Decoder tool; the token is decoded in your browser and is not sent to a server. To see how the encoding works, look at the Base64 Encode/Decode tool.
Frequently asked questions
Is a JWT encrypted?
No, it is only signed; anyone can decode and read the payload.
Is decoding a JWT the same as verifying it?
No; verification requires checking the signature with the key and looking at the exp value.
What is the exp field for?
It states the token's expiration time as Unix time (seconds); after that time the server should reject the token.
Tools mentioned in this guide
More guides
- What Are JSON, Base64 and URL Encoding? Encoding vs Encryption vs Hashing – What do JSON, Base64, URL encoding, HTML entities, SHA and JWT do? Encoding vs encryption vs hashing, with examples that were run and verified.
- How to Create a Secure Password: Length, Entropy and 8 Rules – How to create a secure password: password strength in bits, random-word passphrases, command-line generation and eight practical rules.
- What Is a Hash? SHA-256 vs SHA-1 vs MD5, Examples and Security – What is a hash? SHA-256, SHA-1 and MD5 compared with real outputs: avalanche effect, collision bounds, file verification, salt and password storage.
- What Is a Unix Timestamp (Epoch Time)? Converting to and from Dates, the 2038 Problem – What is a Unix timestamp (epoch) and how do you convert seconds to a date? Manual math, Python, JavaScript and terminal code, milliseconds and 2038.
- How to Convert HEX to RGB Color Codes: Step-by-Step Examples – How to convert a HEX color code to RGB and back: hexadecimal basics, short and 8-digit HEX, darkening math and verified JavaScript and Python snippets.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.