JSON Web Token (JWT): How JWT Works and What Its JSON Payload Really Means
Learn how JWT works: header, payload, signature, registered claims, Base64URL encoding, authentication flow, and the security best practices every developer should know.
That Long String Is Just JSON in Disguise
JSON Web Token, commonly called JWT, is one of the most widely used formats for securely transmitting information between applications. It is commonly used for authentication, authorization, API access, and exchanging claims between a client and a server.
If you have ever seen a token that looks like this:
1eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...you have probably encountered a JWT. Despite its complicated appearance, a JWT has a relatively simple structure: three Base64URL-encoded sections, two of which contain JSON objects.
This article explains how JWT works, what its JSON payload means, how JWT authentication works, and what developers should know before using JWT in production.
What Is a JSON Web Token?
A JSON Web Token (JWT) is a compact, URL-safe format used to represent claims that can be transferred between parties. A JWT can contain information such as:
- User ID
- Username
- Role
- Permissions
- Token issuer
- Expiration time
- Token creation time
- Other application-specific claims
For example, a decoded JWT payload might look like:
1{2 "sub": "12345",3 "name": "Alice",4 "role": "admin",5 "iat": 1793347200,6 "exp": 17933508007}This is ordinary JSON data. The important part is that the JSON payload is then encoded and combined with a header and cryptographic signature to create the final JWT.
What Does JWT Stand For?
JWT stands for JSON Web Token. The name describes its basic design:
JSON
Claims are represented using JSON objects.
Web
JWT is commonly used in web applications and APIs.
Token
The resulting value can represent information about a user or authorization context.
JWT is standardized as an open Internet specification and is commonly used across different programming languages and platforms.
What Does a JWT Look Like?
A typical JWT has three parts separated by periods:
1Header.Payload.SignatureFor example:
1eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ92.3eyJzdWIiOiIxMjM0NSIsInJvbGUiOiJhZG1pbiJ94.5SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c1. Header
JSON describing the token type and signing algorithm, then Base64URL encoded.
2. Payload
JSON claims about the user or context, then Base64URL encoded. Readable by anyone.
3. Signature
Cryptographic signature over header and payload that detects tampering.
Understanding these three components is the key to understanding JWT.
JWT Header
The first section is the header. A decoded JWT header might look like:
1{2 "alg": "HS256",3 "typ": "JWT"4}The two common properties here are:
"alg"
alg specifies the cryptographic algorithm used to create the signature. For example, HS256 means the token uses the HMAC SHA-256 algorithm. Other algorithms include asymmetric signing algorithms such as RS256 or ES256.
"typ"
typ indicates the type of token. For a JWT, this is commonly "JWT". The header is then Base64URL encoded.
JWT Payload
The second section is the JWT payload. This is where the token's claims are stored.
1{2 "sub": "12345",3 "name": "Alice",4 "role": "admin",5 "iat": 1793347200,6 "exp": 17933508007}The payload is JSON, but it is important to understand one major security concept:
A JWT payload is encoded, not automatically encrypted.
What Are JWT Claims?
The properties inside the payload are called claims. A claim is simply a piece of information asserted by the token. JWT claims are commonly divided into three categories:
1. Registered claims
Standardized claim names commonly used by JWT implementations.
2. Public claims
Claim names shared across applications and systems.
3. Private claims
Custom claims agreed upon between the parties using the token.
Registered JWT Claims
Some important registered claims include:
"iss" — Issuer
Identifies who issued the token.
1{2 "iss": "https://example.com"3}"sub" — Subject
Identifies the subject of the token. For authentication systems, this is often a user ID.
1{2 "sub": "user_123"3}"aud" — Audience
Identifies the intended recipient or audience.
1{2 "aud": "my-api"3}"exp" — Expiration Time
Specifies when the token expires. The value is normally a Unix timestamp.
1{2 "exp": 17933508003}"iat" — Issued At
Indicates when the token was issued.
1{2 "iat": 17933472003}"nbf" — Not Before
Specifies the time before which the token should not be accepted.
1{2 "nbf": 17933472003}Custom JWT Claims
Applications can also include custom claims. For example:
1{2 "sub": "12345",3 "role": "admin",4 "department": "engineering"5}Here sub is a standard registered claim, while role and department can be application-specific claims. Avoid putting unnecessary information into tokens because JWTs are commonly sent with API requests and can increase request size.
JWT Signature
The third part is the signature. Conceptually, a signed JWT is created by taking the Base64URL-encoded header, a period, and the Base64URL-encoded payload, and signing them with the selected cryptographic algorithm and key:
1HMACSHA256(2 base64UrlEncode(header) + "." +3 base64UrlEncode(payload),4 secret5)The resulting signature is appended to the token. It allows the receiving application to verify that the token has not been modified.
Is JWT Encryption?
This is one of the most common JWT misconceptions. No, a normal signed JWT is not encrypted. Consider this payload:
1{2 "userId": "123",3 "role": "admin"4}56// Base64URL encoded (NOT encrypted):7eyJ1c2VySWQiOiIxMjMiLCJyb2xlIjoiYWRtaW4ifQAfter encoding it may look like unreadable text, but Base64URL encoding is not encryption. Anyone who has the token can decode the payload.
The signature provides integrity and authenticity verification, not confidentiality.
If sensitive information must be encrypted, a different mechanism such as an encrypted token format may be appropriate.
How JWT Authentication Works
A typical JWT authentication flow looks like this:
1User2 ↓3Login4 ↓5Authentication Server6 ↓7JWT issued8 ↓9Client stores token10 ↓11Client sends JWT with API request12 ↓13Server verifies token14 ↓15Request acceptedStep 1: User Logs In
The user sends credentials to an authentication endpoint. The server verifies them.
1POST /login23{4 "email": "alice@example.com",5 "password": "example-password"6}Step 2: Server Creates a JWT
If authentication succeeds, the server creates a token and signs it with its configured signing key.
1{2 "sub": "12345",3 "role": "user",4 "iat": 1793347200,5 "exp": 17933508006}Step 3: Client Receives the Token
Depending on the application's architecture, the token may be handled using secure cookies or another carefully designed storage strategy.
Step 4: Client Sends the Token
For APIs using bearer authentication, the token is sent with each request. The server verifies its signature and claims.
1Authorization: Bearer eyJhbGciOi...Step 5: Server Authorizes the Request
If the token is valid and the required claims are acceptable, the server can process the request. For example, an endpoint might require:
1{2 "role": "admin"3}JWT Is Not the Same as Authentication
JWT itself does not magically authenticate a user. JWT is a token format. An application decides how that token is issued, transported, stored, validated, expired, revoked, and used for authorization.
You can use JWT as part of an authentication system, but JWT itself is not a complete authentication solution.
Why Does a JWT Look Like Random Text?
JWT uses Base64URL encoding for its header and payload. Each JSON object is encoded into a compact string, and the token is assembled as:
1encodedHeader.encodedPayload.signatureThat's why a JWT looks like a long string rather than readable JSON. Base64URL provides a compact, URL-safe representation.
Can You Decode a JWT?
Yes. The header and payload of a normal JWT can be decoded because they are encoded rather than encrypted, for example by a JWT debugging or development tool. However:
Decoding a JWT is not the same as verifying it.
A decoded token may show you what claims it contains, but only proper signature verification can establish whether the token was signed by a trusted issuer and has not been modified.
JWT Example
The complete JWT is conceptually HEADER.PAYLOAD.SIGNATURE. Consider this simplified setup.
1{2 "alg": "HS256",3 "typ": "JWT"4}1{2 "sub": "12345",3 "name": "Alice",4 "role": "admin",5 "iat": 1793347200,6 "exp": 17933508007}The signature is generated from the encoded header and payload. This gives the server a compact token that carries both identity-related claims and a mechanism for detecting modification.
JWT vs Session-Based Authentication
JWT authentication is often compared with traditional server-side sessions.
1Login2 ↓3Server creates session4 ↓5Session stored server-side6 ↓7Client receives session identifier8 ↓9Client sends identifier10 ↓11Server looks up session1Login2 ↓3Server creates signed JWT4 ↓5Client receives token6 ↓7Client sends token8 ↓9Server verifies tokenNeither approach is automatically better in every situation. Session-based authentication can make server-side session management and revocation straightforward. JWTs can be useful when tokens need to be consumed by multiple services or systems and when stateless verification is desirable. The right choice depends on the architecture.
JWT Security Best Practices
JWT is powerful, but implementation details matter.
1. Always Use HTTPS
Never send authentication tokens over an insecure connection. HTTPS protects the token while it is transmitted between the client and server.
2. Keep Payloads Small
A JWT is commonly attached to API requests. Large payloads increase request size, so keep claims limited to what the application actually needs.
3. Set an Expiration Time
Tokens should generally have an appropriate expiration period. Short-lived access tokens can reduce the impact of token theft.
1{2 "sub": "12345",3 "exp": 17933508004}4. Never Put Passwords in JWT Payloads
The payload can be decoded. It should not be treated as a secure storage location for secrets.
1{2 "username": "alice",3 "password": "secret123"4}5. Verify the Signature
A server should properly validate the JWT signature and relevant claims. Simply decoding a token and trusting its contents is not authentication.
6. Validate Important Claims
Depending on your architecture, validate signature, issuer, audience, expiration, not-before, and expected algorithm. Requirements depend on the application's trust model.
Depending on your architecture, validation may include:
- Signature
- Issuer ("iss")
- Audience ("aud")
- Expiration ("exp")
- Not-before ("nbf")
- Expected algorithm
JWT Access Tokens and Refresh Tokens
Many authentication systems use two different token concepts. An access token is used to access protected resources and is often short-lived. A refresh token is used to obtain a new access token after the current one expires.
1Login2 ↓3Access Token + Refresh Token4 ↓5API requests use Access Token6 ↓7Access Token expires8 ↓9Refresh Token used10 ↓11New Access TokenThe exact implementation and storage strategy should be designed carefully because refresh tokens are highly sensitive credentials.
JWT vs API Keys
An API key is typically a relatively simple secret identifier used to authenticate an application or client. A JWT can contain structured claims and can be cryptographically signed.
1API Key2──────────────3abc123xyz45JWT6──────────────7header.payload.signatureJWTs are particularly useful when the token needs to carry structured claims such as identity, audience, issuer, and expiration.
Where Is JSON Actually Used in JWT?
The name JSON Web Token is not accidental. JSON is used primarily in the header and payload.
1JWT2│3├── Header → JSON → Base64URL4│5├── Payload → JSON → Base64URL6│7└── Signature → Cryptographic signatureBoth the header and the payload are JSON objects before being encoded into the final token. This makes JWT compact while retaining a structured data model.
Common JWT Mistakes
Mistake 1: Treating Base64URL as encryption
Encoding does not hide sensitive information.
Mistake 2: Trusting the payload without verification
A token must be cryptographically verified before its claims are trusted.
Mistake 3: Putting sensitive information in the payload
Avoid passwords, private keys, and other secrets.
Mistake 4: Creating tokens that never expire
Long-lived tokens increase the potential impact of token theft.
Mistake 5: Putting too much data into the token
JWTs should remain relatively small.
Mistake 6: Ignoring issuer and audience validation
In multi-service environments, validating who issued a token and who it was intended for can be important.
When Should You Use JWT?
JWT can be a good fit when:
- APIs need token-based authentication.
- Multiple services need to verify tokens.
- Tokens need to carry structured claims.
- Stateless verification is useful.
- Different applications need a common token format.
JWT may not be the best choice simply because it is popular. For a traditional server-rendered application with straightforward session management, regular server-side sessions may be simpler.
JWT FAQ
Header.Payload.Signature — encoding is not encryption.
The header describes how the token is signed, the payload contains JSON-based claims, and the signature provides a way to verify that the token has not been modified. A JWT payload should be considered readable by anyone who obtains the token.
JWT is ultimately a token format, not a complete authentication system. The security of a JWT-based application depends on how tokens are issued, stored, transmitted, validated, expired, and revoked.