You've noticed this your whole life as a user: your banking app signs you out after a few minutes of inactivity, while the forum you registered on three years ago still greets you by name. That's not an accident or a bank being paranoid for fun. It's two different, deliberate configurations of the same mechanism: session expiration.
This post breaks down how session timeouts actually work, what the OWASP Session Management Cheat Sheet recommends, and how to pick values for your own app.
The cookie underneath
Most web sessions are just a cookie holding a long random ID. The server keeps the real state (who you are, what you're allowed to do) and looks it up by that ID on every request.
Cookies come in two flavors, and the difference matters:
Session (non-persistent) cookies have no Expires or Max-Age attribute.…