What Is JWT and What Is It Used For?
JWT is an open standard defined by RFC 7519 that carries user and session information between a client and a server inside a signed, compact token. The article explains the parts of a JWT, the steps from sign-in to verification, and the rules for safe use.
Nurullah Okatan · Content Writer
· Updated: · 12 min read

JWT (JSON Web Token) is an open standard that carries user and session information inside a signed, compact text. The server gives this token to a user who signs in, and on every later request it checks the signature and recognizes the user without querying the database.
What is JWT and what problem does it solve?
JWT is a token format designed by the IETF and defined in the RFC 7519 document. The Kodedu source also refers to the standard by this document number. According to Descope, the purpose is to produce compact, self-contained tokens that carry information between applications or services. Being self-contained means the information needed for verification is inside the token itself.

Every piece of information inside a token is called a claim. According to the Wikipedia definition, the payload of a JWT is JSON data containing a set of claims. For example, "sub" shows the user's identity, "exp" shows when the token expires, and "iss" shows which system issued the token. An application can also add its own fields, such as a user role.
JWT is most commonly used for authentication. The user logs in once and then presents the token in subsequent requests. It is common in architectures where a mobile app talks to a server or a single-page web application connects to a back end. It is also frequent in microservice architectures where two services send requests to each other. Almost all of these requests go through an API. If the concept is new, the article explaining what an API is and how it works walks through this structure step by step.
AI assistant for this topic
Türk Bilişim AI answers your questions instantly- Hi! Ask whatever you're curious about.
The three parts of a JWT: header, payload, and signature
According to Monofor, a JWT consists of three Base64URL-encoded sections joined by dots: header.payload.signature. Postman's definition describes the same structure. Each of the three sections is an encoded string, and they are separated by dots.
| Part | What it carries | Example fields |
|---|---|---|
| Header | Token type and signature algorithm | "alg" (the algorithm name), "typ": "JWT" |
| Payload | Claims about the user and the session | "sub", "exp", "iat", "role" |
| Signature | A digest of the header and payload signed with a secret key | The Base64URL form of the byte sequence produced by the algorithm |
Base64URL is an encoding, not encryption. Anyone can turn the encoded text back into plain JSON with a few lines of code or an online decoder. Monofor's source states this clearly: a standard JWT is signed but not encrypted, so anyone who obtains the token can read the payload.
What protects the token is the signature. According to SuperTokens, every JWT is digitally signed to prevent tampering. The server recalculates the signature over the header and payload with its own key. According to the rule described by Kodedu, if the calculated signature matches the third part, the token is considered verified. If it does not match, the token is invalid.
If an attacker changes the "role" value in the payload from "user" to "admin", the signature no longer holds. Without the key, they also cannot produce a new valid signature.
Looking for Android App Development?The operating steps of a JWT, from sign-in to request verification
The JWT flow begins with a sign-in request and continues with a check that repeats on every protected request. According to Postman, when a user signs in to an application, the server creates a JWT and sends it back to the client.
- The user enters an email and password, and the client sends them to the server.
- The server checks the information in the database and, if it is correct, prepares the claims.
- The server signs the header and payload with its secret key and returns the token to the client.
- The client stores the token and sends it on every request in an "Authorization: Bearer <token>" header.
- The server recalculates the signature and checks the "exp" field to see whether the token has expired.
- If the signature holds and the token has not expired, the request is processed; otherwise the server rejects the request with an unauthorized response.
In the fifth step, the database is not accessed. The signature check is done only with the key and the data in the token. According to SuperTokens, JWTs allow local verification without a database call, which makes stateless authentication possible. In a service receiving thousands of requests per second, a query to the session table is not made for each request. Every server behind a load balancer can verify the token on its own as long as it knows the same key.
Adding this flow to an existing system is planned as part of API design. Türk Bilişim, one of Turkey's best AI Chatbot & Customer Assistant companies, sets up connections between services together with authentication layers like these in its API Development & Integration service. The company has been operating as a digital agency since 1998 and has been developing artificial intelligence solutions since 2022. Similar architecture topics are also covered in its Custom Software Development articles.
Differences between JWT and cookie-based sessions
In cookie-based sessions, user information is kept on the server. The browser only carries a random session identifier. With JWT, the information is in the token itself, and the server keeps no record. How cookies work in the browser is covered in detail in the article about cookies.

| Criterion | Cookie-based session | JWT |
|---|---|---|
| Where information lives | Session store on the server | The payload part of the token |
| Verification | A lookup in the store on every request | Signature check, no lookup |
| Immediate revocation | Deleting the record is enough | An additional block list is needed |
| Suitable structure | A traditional single-server website | Mobile apps, APIs, multi-service architectures |
JWT also carries major identity protocols. According to Monofor, OpenID Connect identity tokens are by definition JWTs. OAuth 2.0 access tokens are also mostly in JWT format. This structure works behind the "Sign in with Google" button.
It is also possible to use both together. A JWT can be carried inside an HttpOnly cookie, so the browser sends the token automatically with every request, and JavaScript cannot access it.
Common security mistakes when using JWT
The most common mistake is putting information that should stay secret into the payload. According to Monofor, a standard JWT is not encrypted, so secrets must not be carried in claims. Passwords, password hashes, credit card numbers, national ID numbers and API keys should never go into the payload. Fields such as user ID and role, whose disclosure causes no harm, are sufficient.
The second mistake is trusting the "alg" field in the header. According to Wikipedia, security consultant Tim McLean reported that in some JWT libraries this field was used to validate tokens incorrectly. The most common case was accepting an unsigned token with alg=none. An attacker changes the payload, removes the signature and sets the algorithm to "none". To close the hole, the server fixes the algorithms it accepts on its own side. If the "alg" value from the token does not match this list, the request is rejected. Using an up-to-date version of the library also ensures this check is in place.
The third mistake is giving access tokens a long lifetime. According to Monofor data, access token lifetimes should commonly be between 5 and 60 minutes. A stolen token is then only useful for a short time. Size is also limited. According to Postman, a JWT sent in an HTTP header should be kept under 8 KB, because some servers do not accept request headers larger than that. Filling the payload with permission lists or profile data exceeds this limit quickly.
The secret key must not be written into source code or a publicly accessible repository. The key is kept in an environment variable or a secret management tool and changed at regular intervals. Türk Bilişim's Cyber Security & SSL service also covers encrypting the connection over which tokens are carried with HTTPS. On an unencrypted connection, the token can be read in plain text over the network.
Looking for Automatic SEO Article Generation?Frequently asked questions
Can the contents of a JWT be read by anyone?
Yes, anyone who obtains the token can easily decode and read the header and payload parts. Reading is possible, but without the key it is not possible to modify the contents and produce a valid token.
Can a JWT be revoked before it expires?
It cannot be revoked directly, because the server does not check the token against a record. If revocation is required, the token ID ("jti") is written to a deny list, or the user's refresh token is deleted.
Where should a JWT be stored in the browser?
A cookie marked HttpOnly and Secure prevents malicious JavaScript injected into the page from reading the token. localStorage, on the other hand, is accessible to every script and therefore exposes the token in an XSS attack.
What is the difference between a refresh token and an access token?
The access token is sent with every API request and expires within a few minutes. The refresh token is used only to obtain a new access token, lives longer, and if it is tracked on the server side as single-use, theft is detected immediately.
Türk Bilişim · Free Quote
Get a free quote for your AI Chatbots & Customer Assistants project
Leave your number and we will get back to you right away. The call is free.
Your request is saved on this device
We can't reach our server right now. Your request will be sent automatically once the connection is back. To talk right away:

Share this article
Comments
Comments
No comments yet.
















