What is a JWT?
A signed, self-contained token that carries claims the server can verify
Reviewed by Abhijith N M · 24 October 2026 · Editorial standards
A JWT is a compact string with three parts: a header, a payload of claims, and a signature. The server signs it with a secret or private key. Anyone can read the payload; the signature only proves it was issued by the holder of the key and was not altered. The server verifies the signature and checks claims such as expiry and audience. There is no central session lookup, which is the point. It also means a token stays valid until it expires unless you add a revocation list.
What is a JWT? — Visual Breakdown
Header
Algorithm & token type
import jwt, datetime
SECRET = "your-secret-key"
# Create a token
payload = {
"sub": "user_123",
"role": "author",
"exp": datetime.datetime.utcnow() + datetime.timedelta(hours=1),
}
token = jwt.encode(payload, SECRET, algorithm="HS256")
# Verify it later
decoded = jwt.decode(token, SECRET, algorithms=["HS256"])
print(decoded["role"]) # "author"Quick Concept Check
Test your understanding in 15 seconds
Where should you store JWTs to protect against XSS?
Related Concepts
Want hands-on practice building this end-to-end?
Check out the full structured learning path with guided projects and code evaluations.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.