ToolsCourt
BlogJWT Explained: What It Is, How It Works, and When to Use It
Dev8 min read·January 2025

JWT Explained: What It Is, How It Works, and When to Use It

JSON Web Tokens from scratch — header, payload, signature, standard claims, and security best practices.

Try the free tool
No signup. Runs in your browser. Takes 10 seconds.
Open JWT Decoder

What Problem Does JWT Solve?

When a user logs into a website, the server needs to remember who they are for subsequent requests. The traditional solution is session cookies: the server stores session data in a database and gives the client a session ID. The problem: as your application scales to multiple servers, every server needs access to the same session database — creating a bottleneck.

JWT solves this by making authentication stateless. Instead of storing session data server-side, the server issues a token that contains the user's identity and any relevant claims. The client sends this token with every request. Any server can verify the token cryptographically without querying a database.

Anatomy of a JWT

A JWT has three parts separated by dots:
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyXzEyMyJ9.signature

Part 1 (Header):  eyJhbGciOiJIUzI1NiJ9
Decoded:          {"alg": "HS256", "typ": "JWT"}

Part 2 (Payload): eyJzdWIiOiJ1c2VyXzEyMyJ9
Decoded:          {"sub": "user_123", "iat": 1700000000, "exp": 1700003600}

Part 3 (Signature): Verifies authenticity — cannot decode without secret key

How Token Verification Works

  • Client sends request with JWT in Authorization header: Authorization: Bearer eyJhbG...
  • Server splits the token into its 3 parts
  • Server recomputes the signature using its secret key and the header+payload
  • If computed signature matches the token's signature — valid
  • Server checks expiry (exp claim) and other claims
  • If all checks pass — request is authorised

Access Tokens vs Refresh Tokens

TokenTypical ExpiryPurposeStorage
Access Token15 minutesAuthenticate API requestsMemory (JS variable)
Refresh Token7–30 daysGet new access tokensHttpOnly cookie
⚠️ Never store JWTs in localStorage. XSS attacks can steal tokens from localStorage. Store access tokens in memory and refresh tokens in HttpOnly cookies.
💡 Use the ToolsCourt JWT Decoder to inspect any JWT — see all claims, check expiry in real time, and verify the algorithm used.
Ready to try it?
Free, instant, no signup required.
Open JWT Decoder Free →