PrivacyQuick

Cookies & tracking

Session cookies vs persistent cookies explained

A session cookie has no expiry date and is meant to disappear when the browser session ends; a persistent cookie has an Expires or Max-Age attribute and stays until that time or until it's cleared. For consent, what matters is the cookie's purpose, not how long it lasts.

  • Plain English
  • Written for website owners
  • Free to read

A session cookie is a cookie with no expiry date: the browser keeps it only for the current browsing session and drops it when that session ends. A persistent cookie has an Expires date or a Max-Age and survives browser restarts until that time passes or the visitor clears it. That's the whole technical difference, and it's decided by one or two attributes in the Set-Cookie header. What it doesn't decide is whether a cookie needs consent: under EU and UK rules that depends on what the cookie is for, not how long it lives.

This guide explains how each type works, why "session" doesn't always mean "gone when you close the browser", and how lifetime fits into your consent and disclosure obligations. For a broader introduction, start with what website cookies are.

The difference at a glance

TopicSession cookiePersistent cookie
How it's createdNo Expires and no Max-AgeExpires date or Max-Age in seconds
When it's deletedWhen the browser decides the session has endedWhen the expiry passes, or the visitor or site deletes it
Survives a browser restart?Normally no, but session restore can keep itYes
Typical usesServer sessions, carts, form steps, CSRF tokens"Remember me" logins, preferences, consent choice, analytics and ad IDs
Shown in DevTools as"Session" in the Expires / Max-Age columnA date and time

Session and persistent describe lifetime only. A cookie is also first-party or third-party depending on which site set it, and the two classifications are independent: a third-party cookie can be a session cookie, and a first-party cookie can last for years.

How Expires and Max-Age work

The server, or a script on the page, sets a cookie's lifetime when it creates it. Three variations:

Set-Cookie: cart=7f3a91; Path=/; Secure; HttpOnly
Set-Cookie: lang=fr; Path=/; Max-Age=2592000; Secure
Set-Cookie: promo_seen=1; Path=/; Expires=Wed, 30 Jun 2027 12:00:00 GMT

The first is a session cookie, because it has neither attribute. The second is persistent for 2,592,000 seconds, which is 30 days from the moment it's set. The third is persistent until a fixed date and time in GMT.

A few rules worth knowing:

  • Max-Age wins. If a cookie has both attributes, browsers use Max-Age. It's also more robust, because it doesn't depend on the visitor's clock matching the server's.
  • Deleting a cookie means expiring it. There's no delete command. You overwrite the cookie with the same name, domain and path and set Max-Age=0 or an Expires date in the past.
  • Renewal resets the clock. Many tools rewrite their cookie on each visit with a fresh expiry, so a "two-year" cookie can effectively last as long as the visitor keeps coming back.
  • Browsers cap long lifetimes. Chrome limits expiry to 400 days, and Safari shortens cookies set by JavaScript in many situations. A persistent cookie may disappear well before the date its owner set. The details are in cookie lifespans: browser caps and regulator limits.

The same attributes apply when JavaScript writes a cookie:

// Session cookie: no expiry
document.cookie = "step=2; Path=/; Secure; SameSite=Lax";

// Persistent cookie: 180 days
document.cookie = "theme=dark; Path=/; Max-Age=" + 60 * 60 * 24 * 180 + "; Secure; SameSite=Lax";

When does a browser session actually end?

The specification leaves it to the browser to decide when a session ends, and modern browsers often keep it going far longer than people expect.

  • Session restore. If a desktop browser is set to reopen your previous tabs on startup, such as Chrome's "Continue where you left off" or Firefox's option to open previous windows and tabs, it typically restores session cookies too. The session never ended, as far as the browser is concerned.
  • Mobile browsers. On phones, people rarely quit the browser. Session cookies can survive for days or weeks while the app sits in the background.
  • Private windows. Closing all private or incognito windows reliably clears everything from that session, persistent cookies included.
  • Tabs don't matter. Closing a single tab doesn't end the session. Cookies are shared across all tabs of the same browser profile.

So if your security or privacy design depends on a cookie disappearing, don't rely on the session alone. Give the server-side session its own timeout, and treat the client-side cookie as something that may linger.

Don't confuse session cookies with sessionStorage. That web storage API is scoped to a single tab and cleared when the tab closes, and it isn't sent to the server. The consent rules still apply to it, as explained in do localStorage and sessionStorage need consent?

Three things called "session"

"Session" means different things depending on who's talking, which causes confusion in cookie audits:

  1. A session cookie: the technical lifetime described above.
  2. A login or server session: the period during which a server recognizes you, usually through an ID stored in a cookie. That cookie can be session or persistent. A "keep me signed in" option typically turns it into a persistent cookie.
  3. An analytics session: a group of page views that an analytics tool counts as one visit, often ending after a period of inactivity. It's a reporting concept, typically built from persistent cookies that identify the browser.

When a vendor's documentation says a cookie is "used for session tracking", check whether it means the lifetime or the purpose. An analytics cookie that tracks sessions is still an analytics cookie.

Common examples

Typical lifetimes for cookies you'll often find in audits. Defaults change and most are configurable, so check what your own site actually sets.

CookieSet byUsual typePurpose
PHPSESSIDPHP applicationsSession (by default)Server-side session ID
JSESSIONIDJava web serversSession (by default)Server-side session ID
ASP.NET_SessionIdASP.NET applicationsSessionServer-side session state
wordpress_logged_in_…WordPressSession, or persistent with "Remember Me"Keeps a user signed in
Consent cookieYour consent toolPersistentRemembers the visitor's choice
_gaGoogle AnalyticsPersistent (Google documents a two-year default)Distinguishes browsers for analytics
_fbpMeta PixelPersistentIdentifies browsers for ad measurement

To see the real values on your own site, open DevTools on a page and look at the Expires / Max-Age column. Our guide to checking cookies in Chrome DevTools walks through it, including how to spot cookies that only appear after consent.

The ePrivacy Directive, Art. 5(3), and the UK's PECR reg. 6 require consent for storing or accessing information on a visitor's device unless it's strictly necessary for a service the visitor requested, or needed only to transmit a communication. Neither rule distinguishes between session and persistent cookies. A cookie's lifetime doesn't make it exempt, and it doesn't make it need consent.

Duration doesn't decide consent; purpose does. A session cookie used for analytics needs consent. A persistent cookie that stores the visitor's consent choice doesn't.

Lifetime still matters in three ways:

  • Exemptions are easier to justify for short-lived cookies. The Article 29 Working Party's Opinion 04/2012 on the cookie consent exemption treated many exempt cookies, such as user-input, authentication and load-balancing cookies, as typically session cookies. It also noted that some exempt cookies, like a cookie recording a preference, can reasonably persist for longer. A "necessary" cookie with a lifetime far beyond its function is harder to defend. Our strictly necessary cookies guide covers the test.
  • Lifetimes must be proportionate. The GDPR's storage limitation principle (Art. 5(1)(e)) applies when cookies hold personal data, and some regulators set expectations for cookie lifetimes. The CNIL, for example, has said that cookies used for exempt audience measurement shouldn't last more than 13 months.
  • Lifetimes must be disclosed. GDPR Art. 13(2)(a) requires you to say how long personal data is stored, and regulators expect cookie policies to list each cookie's duration. Saying "session" or giving the actual period is part of informing visitors.

Don't confuse a cookie's lifetime with how long the consent itself lasts. The consent cookie may expire after a set period, but how often you should ask visitors again is a separate question, covered in how long cookie consent lasts.

Choosing the right lifetime

If you set cookies yourself, pick the shortest lifetime that does the job:

  • Server sessions, carts for guests, multi-step forms and CSRF tokens: session cookies, with a server-side timeout.
  • "Remember me" logins: a persistent cookie with a defined period, offered as an explicit option rather than the default, and invalidated on the server when the user signs out.
  • Preferences such as language or theme: persistent, for a period that matches how long the setting is useful.
  • Consent choice: persistent, for a period that matches your re-consent policy, and well under browser caps so it behaves predictably.
  • Analytics and advertising IDs: usually set by the vendor's script. Many vendors let you shorten the expiry, which reduces how long a visitor can be recognized. They still need consent where the law requires it.

Whatever you choose, add the Secure, HttpOnly and SameSite attributes where they fit. They do more for security than a short lifetime does.

Next steps

  1. List every cookie your site sets, with its lifetime as the browser reports it.
  2. For each one, decide its purpose and category first; let lifetime follow from the purpose.
  3. Shorten lifetimes that are longer than their purpose needs, especially for cookies you treat as strictly necessary.
  4. Record each cookie's duration in your cookie policy, and update it when a vendor changes its defaults.
  5. Re-check after adding plugins or tags, since they often bring persistent cookies with them.

A free PrivacyQuick scan loads your pages in a real browser and records the cookies and storage it finds, classified against a database of known cookies. Its cookie policy generator can keep the cookie table in your policy updated from those scans.

Frequently asked questions

Are session cookies safer than persistent cookies?

Not inherently. A session cookie limits how long an identifier sticks around, which reduces some tracking and theft risk, but a stolen session cookie can still be used while it's valid. Security depends more on attributes like Secure, HttpOnly and SameSite.

Do session cookies need consent?

Only if they aren't strictly necessary. A session cookie that keeps a shopping cart working is exempt in the EU and UK, while a session cookie set by an analytics or advertising tool still needs consent first.

How do I make a cookie a session cookie?

Set it without an Expires or Max-Age attribute. The browser then treats it as a session cookie and drops it when the browsing session ends, subject to session restore settings.

Is a third-party cookie always persistent?

No. Whether a cookie is first-party or third-party depends on which site set it, and whether it's session or persistent depends on its expiry attributes. The two classifications are independent.

Check your own website in 30 seconds

Our free scanner lists every cookie and tracker your site sets, sorted into categories, before you add a banner.

Run a free cookie scan Start free

This guide is general information, not legal advice. Laws and regulator guidance change; check the current rules for your situation or ask a lawyer.