What is a JWT Token?

JSON Web Token (JWT) is an open standard (RFC 7519) for securely transmitting information between parties as a JSON object. JWTs are commonly used for authentication and authorization in web applications.

JWT Structure

A JWT consists of three parts separated by dots (.), each Base64URL encoded:

header.payload.signature

1. Header

Contains metadata about the token, typically the signing algorithm (alg) and token type (typ).

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

2. Payload

Contains the claims—statements about the user and additional metadata.

{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022,
  "exp": 1516242622
}

3. Signature

Created by signing the encoded header and payload with a secret key. Verifies the token hasn't been tampered with.

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

Common JWT Claims

Claims are pieces of information about the subject (user). There are three types:

Registered Claims (Standard)

ClaimNameDescription
issIssuerWho issued the token
subSubjectWho the token is about (user ID)
audAudienceIntended recipient
expExpirationWhen the token expires (Unix timestamp)
nbfNot BeforeToken not valid before this time
iatIssued AtWhen the token was created
jtiJWT IDUnique identifier for the token

Custom Claims

You can add any custom claims your application needs, such as:

  • name — User's name
  • email — User's email
  • role — User's role (admin, user, etc.)
  • permissions — Array of permissions

How JWT Authentication Works

  1. Login: User sends credentials to the server
  2. Token Creation: Server verifies credentials and creates a JWT
  3. Token Storage: Client stores the JWT (usually in localStorage or cookies)
  4. Authenticated Requests: Client sends JWT in the Authorization header
  5. Token Verification: Server verifies the signature and checks expiration
// Sending JWT in Authorization header
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...

JWT Security Best Practices

✓ Do

  • • Use strong secrets and asymmetric keys (RS256) for production
  • • Set short expiration times (exp claim)
  • • Validate all claims on the server
  • • Use HTTPS for all token transmission
  • • Store tokens securely (httpOnly cookies preferred)

✗ Don't

  • • Don't store sensitive data in the payload (it's not encrypted)
  • • Don't use weak secrets like "secret"
  • • Don't ignore token expiration
  • • Don't store tokens in localStorage if XSS is a concern
  • • Don't use the none algorithm in production

Common Signing Algorithms

AlgorithmTypeUse Case
HS256SymmetricSimple apps, same party signs and verifies
RS256AsymmetricDistributed systems, public key verification
ES256AsymmetricModern apps, smaller signature size

Decode Your JWT

Use our JWT decoder to inspect any token's header, payload, and signature. See expiration status and all claims at a glance.

Open JWT Decoder →