What is a session? Explained with a wristband at an event
A session is the logged-in period when a website keeps recognising you through a random code your browser shows with each click. Explained with a wristband: checked once at the entrance, then shown at every door.
- Author
Umair Mateen- Published
- Reading time
- 5 min
- Category
- Engineering
In one sentence: A session is the period after you log in during which a website keeps recognising you, using a random code your browser shows with every click, so you do not have to type your password again on each page.
The everyday picture
Picture a large conference in a big building. At the entrance, a desk checks your ticket and your ID. Once you pass, they snap a paper wristband on you with a random number printed on it.
The desk writes that number on its guest list, next to your name. From then on, staff at each hall door just glance at your wristband and check the list. Nobody asks for your ID again.
When you leave for good, or the day ends, the desk crosses your number off. The wristband stops opening doors. A website session works the same way: logging in is the entrance check, and the session is your wristband.
You prove who you are once and get a wristband (the session ID). Every door checks the band against the guest list, until the list crosses it off.
How it works, step by step
- Logging in (the entrance desk): you give your username and password, and perhaps a code from your phone. The website checks them once.
- The session ID (the wristband): the website creates a long, random code that means nothing on its own. It sends this to your browser, usually inside a cookie, which your browser then keeps.
- The session store (the guest list): on its own side, the website records that this code belongs to you, along with things like what you are allowed to do.
- Each request (each hall door): every time you click, your browser sends the code along. The website looks it up and knows it is you. The web's basic rules forget every visit, so without this code each click would be a stranger at the door.
- Ending the session (crossing you off the list): when you log out, or after you have been inactive too long, or after a set maximum time, the website deletes or cancels the record. The old code no longer works, even if someone still has it.
Try it · Put it in order
Put a login session in the right order
Tap the steps in the order they happen.
Where the picture stops
- A paper wristband is hard to copy without you noticing. A session ID is just text. If someone steals it, they can pose as you until the session ends. This is called session hijacking, which is why the code must be long, random and only sent over encrypted connections.
- Security guidance says a website should give you a brand-new code every time you log in and cancel any old one. An event would rarely swap your wristband at the door, but websites must.
- Some systems keep no guest list. They hand out a signed pass that carries your details itself, and the website checks the signature instead. That is a different design with its own trade-offs.
Why it matters for your business
- Customers: sessions are what let people log in once and move freely around your app or shop. Badly tuned sessions either log people out too often or keep them logged in for too long.
- Risk: while a session lasts, its code works like a key. OWASP and NIST both say logging out must cancel the session on the website's side, not just delete the code from the browser.
- Right-sized timeouts: guidance describes two limits: one for inactivity and one for the total length of a session. A banking or admin tool should use shorter limits than a recipe site. Ask your developers what yours are and why.
- Cost and reliability: MDN advises using a well-regarded framework for sessions rather than building your own. That saves time and avoids known mistakes.
An example
Imagine a 15-person bookkeeping firm with a client portal. A client logs in, gets a session, and moves between invoices without re-entering a password. If they walk away from a shared office computer, the portal ends the session after a period of inactivity. If they click "Log out", the portal crosses the code off its list straight away, so anyone who sits down next cannot carry on as them.
Frequently asked questions
What is the difference between a session and a cookie?
A cookie is a small note your browser stores and sends back to a website. A session is the logged-in period itself. The session ID is often carried in a cookie, like a number printed on a wristband.
Why do websites log me out automatically?
Most sessions end after a period of inactivity, after a maximum total time, or both. This limits the damage if you leave a device unattended or someone copies your session code.
Is "remember me" the same as a session?
Not quite. It keeps you signed in across browser restarts, usually with a longer-lasting cookie. NIST guidance limits when such features may stand in for logging in again.
Does closing the browser end my session?
Sometimes, but not always. It depends on how the website set its cookie and its timeouts. Clicking "Log out" is the reliable way to end it.
Related explainers
- What is a cookie? Explained with a cloakroom ticket
- What are SSO and 2FA? Explained with a hotel key card and a PIN
- What is role-based access? Explained with office keycards
- What is encryption? Explained with a sealed envelope
The DevDrift builds web platforms with secure logins and sensible session settings: see how.
Sources
Could you explain this to a colleague now?
Mark it and posts that mention it will show a tick. Saved in this browser only.