Sessions vs JWT vs Cookies: Understanding Authentication Approaches

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
Search for a command to run...

Learning web development in public. Writing simple, real-world explanations about web development concepts. Helping beginners understand why things work, not just how.
No comments yet. Be the first to comment.
Every day, millions of users upload photos, videos, stories, and reels to Instagram. From a user's perspective, the process appears simple: select media, apply filters, add a caption, and tap "Post."
Building Offline-First Messaging Apps: How Messages Work Without Internet Modern messaging applications have transformed the way people communicate. Whether it's chatting with friends, collaborating w
In this article we'll explore about the Expo Router and React Navigation and answer which one to use in 2026. If you build mobile apps using React Native, one thing becomes obvious very quickly: Navig

Modern mobile apps are no longer just a collection of screens connected together. Apps like Instagram, WhatsApp, Uber, and Netflix operate at massive scale with millions of users, real time systems, o
In this article we'll be exploring react.js and the things of react.js that makes it popular and stand out among other libraries ( no fight over library vs framework ). We'll go through: What problem

Shkaai
68 posts
Authentication is something you’ll deal with in almost every backend project.
But the confusion usually starts here:
What are sessions?
What are cookies?
What is JWT?
And why do people argue about them so much?
Let’s break everything down step by step.
A session is a way for the server to remember a user.
When a user logs in:
Server creates a session (some data stored on server)
Server generates a unique session ID
Sends that session ID to the client (usually via cookies)
Now for every request:
Client sends session ID
Server looks it up
If found → user is authenticated
User logs in → Server creates session → Session stored in DB/memory
→ Session ID sent to browser
Next request → Browser sends session ID → Server validates → Access granted
Data is stored on the server
Client only holds a reference (session ID)
A cookie is just a small piece of data stored in the browser.
That’s it.
Cookies are not authentication by themselves — they are just a storage mechanism.
Session IDs
JWT tokens
User preferences
Set-Cookie: sessionId=abc123
Browser automatically sends cookies with every request to that domain.
Cookies are used with both sessions and JWT.
JWT stands for JSON Web Token.
It’s a self-contained token that carries user data.
header.payload.signature
Example:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
.eyJ1c2VySWQiOjEyMywicm9sZSI6InVzZXIifQ
.signature
User logs in
Server generates JWT
Sends it to client
Client stores it (cookie/localStorage)
Client sends JWT in every request
Server does NOT store anything.
It just verifies the token:
jwt.verify(token,SECRET_KEY);
If valid → user is authenticated
Data is stored inside the token
Server does not need to remember anything
This is the core difference.
Server stores user data
Needs memory/database
Every request depends on server state
Client → Session ID → Server → Lookup session → Response
Server stores nothing
Token contains everything
Each request is independent
Client → JWT → Server → Verify → Response
Session
JWT
Session
JWT
Session
Safer by default
Server controls everything
JWT
Risky if token is leaked
Cannot be invalidated easily
Session
JWT
Session
JWT
You want better security control
You are building traditional web apps
You need easy logout handling
You don’t care much about scaling yet
You are building APIs
You need scalability
You have multiple services (microservices)
You want stateless architecture
You need automatic request sending
You are working with browsers
You want secure storage (HttpOnly, Secure flags)
Cookies → storage mechanism
Sessions → stateful authentication (server-based)
JWT → stateless authentication (token-based)
If you remember just this, you’re already ahead of most beginners.
Session = “Server remembers you”
JWT = “You carry your identity”
Cookie = “Browser stores stuff for you”