What is a JWT Token? How to Decode and Use JWTs in 2026
If you have worked with any modern authentication system — OAuth 2.0, OpenID Connect, or practically any REST API with login — you have almost certainly encountered a JWT. They appear in Authorization headers, cookies, and URL parameters. They look like gibberish: a long string with two dots in it.
This guide explains exactly what a JWT is, how it works, what is safe to put in one, and how to decode one without sending it to a third-party server.
What is a JWT?
JWT stands for JSON Web Token (pronounced "jot"). It is a compact, URL-safe way to represent claims between two parties. The standard is defined in RFC 7519.
A JWT looks like this:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyIsIm5hbWUiOiJBbGljZSIsImlhdCI6MTc1MzkwMDAwMCwiZXhwIjoxNzUzOTg2NDAwfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
Three base64url-encoded sections separated by dots. Each section serves a distinct purpose.
The Three Parts of a JWT
Part 1: Header
The header describes the token type and the signing algorithm:
{
"alg": "HS256",
"typ": "JWT"
}
Common algorithm values: HS256 (HMAC-SHA256), RS256 (RSA-SHA256), ES256 (ECDSA P-256).
Part 2: Payload
The payload contains claims — assertions about the user and metadata:
{
"sub": "user_123",
"name": "Alice Nguyen",
"email": "alice@example.com",
"roles": ["admin", "editor"],
"iat": 1753900000,
"exp": 1753986400
}
Part 3: Signature
The signature is computed over the encoded header and payload:
HMACSHA256(
base64url(header) + "." + base64url(payload),
secret
)
If an attacker modifies the payload, the signature will not match and the server will reject the token.
Standard JWT Claims
| Claim | Full Name | Description |
|---|---|---|
sub | Subject | The principal the token is about (usually a user ID) |
iss | Issuer | Who issued the token |
exp | Expiration Time | Unix timestamp after which the token is invalid |
iat | Issued At | Unix timestamp when the token was issued |
aud | Audience | The intended recipients of the token |
nbf | Not Before | Token must not be accepted before this timestamp |
jti | JWT ID | Unique identifier — prevents replay attacks |
How JWT Authentication Works
- User logs in — client sends credentials to the auth server.
- Server issues JWT — if credentials are valid, the server creates a signed JWT and returns it.
- Client stores the JWT — typically in
localStorage,sessionStorage, or anhttpOnlycookie. - Client sends JWT with every request — in the
Authorization: Bearer <token>header. - Server verifies the signature — if the signature matches, the claims are trusted without any database lookup.
- Token expires — when
expis reached, the client must re-authenticate or use a refresh token.
The key advantage: the server is stateless. It does not store session data, making JWTs ideal for microservices and distributed systems.
JWT Security: What You Must Know
Never store sensitive data in the payload
The JWT payload is encoded, not encrypted. Anyone with the token can decode it with atob(). Never include passwords, credit card numbers, or PII in a JWT payload.
Always verify the signature server-side
Client-side JWT decoding is only for reading claims (displaying a username, checking expiry for UI purposes). Authorisation decisions must happen server-side after verifying the signature.
Use short expiration times
Because JWTs cannot be revoked once issued (without a blocklist), keep access tokens short-lived (15 min to 1 hour) and pair them with longer-lived refresh tokens.
Prefer httpOnly cookies over localStorage
Storing JWTs in localStorage exposes them to XSS attacks. An httpOnly cookie cannot be read by JavaScript, providing better protection.
Common JWT Algorithms
HS256 (HMAC-SHA256)
Uses a single shared secret for signing and verification. Simple to set up. Suitable for monolithic applications or microservices that share a secret.
RS256 (RSA-SHA256)
Uses an RSA private key to sign and a public key to verify. The public key can be distributed freely (e.g. via a JWKS endpoint). Preferred for third-party API access and OpenID Connect.
ES256 (ECDSA P-256)
Elliptic curve variant of RS256. Produces smaller signatures (64 bytes vs 256 bytes for RS256) with equivalent security. Increasingly preferred for performance-sensitive systems.
Handling Token Expiry and Refresh Tokens
function isTokenExpired(token) {
try {
const payload = JSON.parse(atob(token.split('.')[1]))
return payload.exp * 1000 < Date.now()
} catch {
return true
}
}
async function getValidToken() {
const accessToken = localStorage.getItem('access_token')
if (!accessToken || isTokenExpired(accessToken)) {
const refreshToken = localStorage.getItem('refresh_token')
const res = await fetch('/auth/refresh', {
method: 'POST',
body: JSON.stringify({ refresh_token: refreshToken }),
headers: { 'Content-Type': 'application/json' }
})
const { access_token } = await res.json()
localStorage.setItem('access_token', access_token)
return access_token
}
return accessToken
}
Decode a JWT Instantly with IRJSON
IRJSON's JWT decoder reads the header and payload entirely in your browser using atob(). Your token is never sent to any server.
Frequently Asked Questions
Is a JWT encrypted?
A standard JWT (JWS — JSON Web Signature) is signed but not encrypted. The header and payload are only base64url-encoded. An encrypted JWT is called a JWE (JSON Web Encryption) and has a 5-part structure. Never put passwords or sensitive PII in a standard JWT.
Can I decode a JWT without the secret?
Yes. The header and payload are only base64url-encoded — anyone can decode them. The secret is only needed to verify the signature. IRJSON decodes your token payload without requiring the secret.
What is the difference between JWT and a session?
A session stores state on the server; the client holds only a session ID cookie. A JWT stores state in the token itself — the server is stateless and just verifies the signature. JWTs are better for distributed systems; sessions are simpler for monolithic web apps.
Decode your JWT token securely
IRJSON's free JWT decoder works 100% in your browser. Your token never leaves your device.
Open JWT Decoder →