JWT Authentication Explained: How JSON Web Tokens Work

May 7, 2026 • 9 min read • Try the free JWT Decoder →

JSON Web Tokens (JWTs) are everywhere in modern web development — used for authentication, authorization, and secure information exchange between services. Yet many developers use them without fully understanding how they work, which leads to security vulnerabilities and incorrect implementations.

This guide explains JWTs from first principles: their structure, how signing works, when to use them, and how to use them safely.

What Is a JWT?

A JSON Web Token is a compact, URL-safe means of representing claims between two parties. It is defined by RFC 7519.

A JWT looks like this:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

It has three parts separated by dots: Header . Payload . Signature

The Three Parts of a JWT

1. Header

The header is a Base64URL-encoded JSON object that declares the token type and signing algorithm:

{
  "alg": "HS256",
  "typ": "JWT"
}

Common algorithms: HS256 (HMAC-SHA256, symmetric), RS256 (RSA-SHA256, asymmetric), ES256 (ECDSA-SHA256, asymmetric).

2. Payload

The payload contains the claims — statements about the user or system, plus metadata. Standard registered claims include:

{
  "sub": "user_abc123",
  "iss": "https://auth.example.com",
  "aud": "https://api.example.com",
  "exp": 1735689600,
  "iat": 1735686000,
  "name": "Jane Smith",
  "role": "admin"
}
Important: The payload is only Base64URL-encoded, NOT encrypted. Anyone who holds the token can decode and read the payload. Never put sensitive data (passwords, credit card numbers, SSNs) in a JWT payload.

3. Signature

The signature verifies that the token hasn't been tampered with. It is computed as:

HMACSHA256(
  base64UrlEncode(header) + "." + base64UrlEncode(payload),
  secret
)

For HS256, the same secret is used to both sign and verify. For RS256, a private key signs the token and the corresponding public key verifies it — this is generally more secure for distributed systems.

How JWT Authentication Works (Step by Step)

  1. Login: User sends credentials (username + password) to the auth server
  2. Token issuance: Server validates credentials and returns a signed JWT
  3. Client storage: Client stores the JWT (localStorage, sessionStorage, or an HttpOnly cookie)
  4. API requests: Client sends the JWT in the Authorization header: Bearer <token>
  5. Verification: Server validates the signature, checks expiry (exp), and reads claims
  6. Response: If valid, server processes the request; if expired or invalid, returns 401

Signing Algorithms Compared

AlgorithmTypeUse CaseRecommendation
HS256SymmetricSingle serviceOK if secret is strong and private
RS256AsymmetricMicroservicesPreferred — public key can be shared
ES256AsymmetricHigh-securityBest — smaller keys, same security as RS256
noneNoneNeverNever use — tokens can be forged

JWT Security Best Practices

Debug your tokens: Use NeatJSON's JWT Decoder to instantly decode any JWT and inspect its header and payload — no data is sent to any server.

JWT vs Session Tokens

AspectJWTSession Token
Storage (server)Stateless — no server storage neededRequires session store (DB, Redis)
ScalabilityExcellent — any server can verifyRequires sticky sessions or shared store
RevocationHard — must wait for expiryEasy — delete from store
SizeLarger (hundreds of bytes)Small (random string)
Best forMicroservices, APIsTraditional web apps

Frequently Asked Questions

What does JWT stand for?

JWT stands for JSON Web Token. It is an open standard (RFC 7519) for securely transmitting information between parties as a signed JSON object.

Can I decrypt a JWT?

Standard JWTs are signed, not encrypted. The payload is only Base64URL-encoded and can be decoded by anyone. If you need encrypted JWTs, use JWE (JSON Web Encryption) instead.

How do I invalidate a JWT before it expires?

Options include: maintaining a token blacklist (check against it on each request), using very short expiry times with refresh token rotation, or encoding a token version in the payload and incrementing it on logout.

Related Guides