A cookie on a website is a small text file that a site asks your browser to store, and that the browser sends back on later requests to the same site. It typically holds a name, a value, an expiry date, and the domain that set it. The boundary matters: a cookie holds data only, never a program, and it can't reach into other sites' storage or scan your hard drive.

You'll meet them constantly even when you never notice. Sign in to an email account and a session cookie remembers you between page loads. Add a shirt to a shopping cart and a cookie keeps it there while you keep browsing. Dismiss a newsletter banner and a cookie stops the banner reappearing on every page. Load a page with an embedded video and a third-party cookie may travel with that embed.

The confusion starts with the metaphors. People hear "cookie" and picture tracking software, malware, or a file that follows them around the internet. None of those descriptions is accurate for the standard cookie itself, and the distinction matters when you decide what to clear and what to block. This article defines the mechanism, separates it from the technologies it gets blamed for, and shows where cookies fail in practice.

The most useful mental model is a coat-check ticket. The website hands your browser a numbered slip, keeps the coat (your session data) on its own server, and asks for the slip back on your next visit. The ticket carries no coat. It just proves which coat belongs to you. That's why clearing cookies logs you out: the server still has the session, but your browser lost the number.

The Text File That Holds a Name, Value, Expiry, and Two Domains

A single cookie is a key-value pair wrapped in attributes. A typical one set by an online store might read: name cart_id, value 8f3a21, domain .example-store.com, path /, expiry 30 days from creation, and flags Secure and HttpOnly. Size limits are tight. According to the HTTP State Management Mechanism specification, RFC 6265, published by the Internet Engineering Task Force, browsers must support at least 4,096 bytes per cookie and at least 50 cookies per domain.

The two domain fields confuse people because they appear twice. The Domain attribute tells the browser which hosts may receive the cookie. The Host-Only flag, which applies when no Domain attribute is set, restricts the cookie to the exact host that created it. A cookie set on www.example.com with no Domain attribute won't travel to shop.example.com. Set the Domain attribute to .example.com and it will. That single setting explains a common support ticket: a login that works on the main site but silently fails on a subdomain.

Expiry comes in two forms. A persistent cookie carries an Expires or Max-Age attribute and survives a browser restart until that moment passes. A session cookie carries neither, so it lives in memory and dies when the browser closes. Chrome and Firefox both offer "continue where you left off" style session restore, which can preserve session cookies across restarts. That's a browser feature, not a cookie property, and it surprises people who expect closing the window to end a session.

The flags are the security layer. Secure means the cookie travels only over HTTPS. HttpOnly means JavaScript running on the page can't read it, which blunts cross-site scripting attacks that try to steal session tokens. SameSite controls whether the cookie is attached to cross-site requests, and its three values (Strict, Lax, and None) determine whether a cookie follows you from a link on another site. According to Chrome's own documentation, SameSite=Lax has been the browser's default for cookies without an explicit setting since Chrome 80, released in February 2020. Firefox and Edge made similar moves. That default change quietly altered how countless older sites behaved.

Each cookie belongs to one origin, roughly one scheme-plus-domain-plus-port combination. A cookie set by https://example.com won't be sent to http://example.com if it carries the Secure flag, and it won't be visible to https://other.com at all. The browser enforces this, not the website. That enforcement is the reason cookies count as a controlled mechanism rather than an open channel.

Four Concrete Examples You Have Already Met Today

The first is authentication. When you log in, the server verifies your password, creates a session record, and sets a cookie holding a session identifier. Every subsequent request carries that identifier, which is how the site knows it's still you. The cookie usually carries HttpOnly and Secure flags because it's the most valuable item in the jar. According to the Open Worldwide Application Security Project, known as OWASP, session identifiers should be long, random, and rotated at login to limit fixation attacks. That's a cookie doing essential work.

The second is the shopping cart. A store that doesn't require an account can still remember three items because a cookie holds a cart token. The cart contents live server-side; the cookie is the claim ticket. If you clear cookies mid-session, the cart empties, and that's the mechanism working as designed rather than a bug. Many stores also set a short-lived cookie to hold a discount code until checkout.

The third is preference storage. Choosing dark mode, a language, or a currency often writes a cookie with a long expiry so the site renders correctly on your next visit. These are low-risk cookies with little personal data, which is why they rarely appear in consent banners. A site that stores a region code like en-GB in a cookie is doing nothing more invasive than remembering a dropdown selection.

The fourth is analytics and advertising. A third-party script embedded in a page can set its own cookie under its own domain, which is why a news site can show you an ad for a product you viewed elsewhere. These cookies are the ones consent rules target. They're also the ones most likely to be blocked by default, because browsers and extensions treat third-party tracking as a category rather than a case-by-case judgment.

Cookies Are Not Viruses, Not Passwords, and Not the Only Storage

Three confusions deserve direct correction. First, a cookie is not a virus. It's a passive data file. It cannot execute, install, or replicate. The risk comes from what it holds, such as a session token, and from who can read it. Second, a cookie is not your password. The server never needs to store your password in a cookie, and a well-built site doesn't. It stores a session identifier that maps to server-side state. Third, a cookie is not the same as local storage or a cache.

Modern browsers offer several storage mechanisms, and each behaves differently. The table below compares them on the dimensions that actually change your decision about what to clear.

Storage type Typical size limit per origin Sent to the server automatically Lifetime Typical use
Cookie 4 KB per cookie, at least 50 per domain (RFC 6265 floor) Yes, on every matching request Session or persistent until expiry Sessions, preferences, tracking
localStorage 5 MB per origin in Chrome and Firefox No Until cleared by code or user Draft content, UI state
sessionStorage 5 MB per origin No Until the tab closes Single-tab form state
IndexedDB Disk-limited, often hundreds of MB No Until cleared Offline apps, large datasets
HTTP cache Disk-limited No Governed by cache headers Static assets, images, scripts

The table's key row is the second column. Cookies are the only mechanism that travels with every request to the matching domain, which is exactly why they're useful for sessions and exactly why they're watched. A 4 KB cookie attached to every image request is overhead; a 5 MB localStorage entry that never leaves the browser is not. If a site needs to remember something on the server, it uses a cookie. If it only needs to remember something on your device, it typically uses localStorage.

One misuse deserves naming. Marketing teams sometimes stuff analytics identifiers, ad-click IDs, and preference blobs into a single first-party cookie to dodge third-party blocking. This works technically but creates a privacy and performance problem: the cookie grows, travels on every request, and can breach the 4 KB limit, causing the browser to silently drop it. When a site's personalization stops working after a few weeks, an oversized cookie is a common cause, and the fix is server-side storage plus a short identifier.

First-Party and Third-Party Cookies Split the Privacy Debate

A first-party cookie is set by the domain shown in your address bar. A third-party cookie is set by a different domain, usually through an embedded script, image, or iframe on the page you're viewing. That's the whole distinction. It has nothing to do with the cookie's content and everything to do with who sets it.

The consequences diverge sharply. A first-party session cookie is usually necessary for the site to function, so blocking it breaks login. A third-party advertising cookie is optional for the page to render, so blocking it costs the site revenue and costs you nothing visible. That asymmetry is why browsers treat the two categories differently. According to the Electronic Frontier Foundation, third-party cookies are the primary mechanism by which ad networks correlate your activity across unrelated sites. The EFF is a digital-rights organization, so read that claim as advocacy informed by technical fact rather than a neutral measurement.

Regulation followed the distinction. The EU's ePrivacy Directive, as implemented nationally, requires consent before storing or reading information on a user's device unless the storage is strictly necessary for a service the user requested. In practice, that means session and security cookies can usually be set without a banner, while analytics and advertising cookies need consent in the EU. The UK's Information Commissioner's Office publishes guidance stating the same principle: consent must be freely given, specific, informed, and withdrawable. The rules differ by jurisdiction, so a site that complies in one country may not comply in another.

Here's the failure case worth knowing. A global retailer once deployed a consent banner on its EU storefront that blocked third-party scripts until acceptance. Its US storefront had no banner, and its analytics cookies loaded immediately. The company's dashboards compared EU and US conversion rates without noting the instrumentation gap, concluded that EU users were less engaged, and cut EU marketing spend. The data was distorted by the measurement setup, not by user behavior. Consent architecture shapes analytics, and analysts who forget that draw wrong conclusions.

The practical upshot for a visitor: clearing third-party cookies is low-risk and usually improves page speed. Clearing first-party cookies logs you out of everything. Blocking all cookies breaks most of the modern web, which is why "block all" is a setting almost nobody keeps for long.

Session and Persistent Cookies Fail in Predictable Ways

Session cookies and persistent cookies differ only in whether they carry an expiry. The consequences of that difference show up in support queues. A session cookie disappears on browser close, so a user who quits the browser and returns must log in again. A persistent cookie with a 30-day expiry keeps the user signed in, but also keeps them signed in on a shared computer if they never log out.

The failure modes cluster around clocks, domains, and size. If a user's system clock is badly wrong, a cookie with an Expires date in the past is discarded immediately. If a site sets a cookie on a subdomain but reads it on the apex domain, the cookie never arrives, and the user experiences a login loop with no error message. If a cookie exceeds the size limit, the browser drops it silently, and the site's "remember me" feature quietly stops working.

According to RFC 6265, a cookie with an Expires attribute in the past is treated as expired and should be removed. That rule looks trivial until you meet a server misconfigured to emit dates in the wrong timezone, which causes cookies to expire hours early or late. Support teams see this as intermittent login failures that clear up on their own. The cause is a clock or format mismatch on the server, not the user's device.

HTTP Strict Transport Security, or HSTS, is a related failure. A site that previously served cookies over HTTP and later enforced HTTPS can break sessions for users whose browsers cached the old behavior. The fix is a deliberate cookie migration, setting Secure on new cookies while tolerating old ones briefly. Sites that push the change too fast log out their entire user base at once. That's a self-inflicted edge case, and it happens more often than product teams expect.

Deleting, Blocking, and Allowing Cookies Without Breaking Your Browser

You don't need to clear cookies blindly. A short sequence handles most situations, and each step has a visible control in the major browsers. Names vary slightly between Chrome, Firefox, Safari, and Edge, but the structure is the same.

1: Open your browser's settings and find the privacy or cookies section. In Chrome, it's Settings β†’ Privacy and security β†’ Third-party cookies. In Firefox, it's Settings β†’ Privacy & Security β†’ Cookies and Site Data. In Safari on macOS, it's Settings β†’ Privacy β†’ Manage Website Data. In Edge, it's Settings β†’ Cookies and site permissions β†’ Manage and delete cookies and site data. 2: Review third-party cookies first. Blocking them is low-risk for most people and stops cross-site tracking. Expect some embedded video players and social widgets to stop working until you allow that specific site. 3: Delete site data for one problem site rather than all sites. Every browser above offers a per-site list. This preserves logins elsewhere while fixing the one site that misbehaves. 4: If a login fails after deleting, clear that site's cookies specifically, then reload and sign in again. A stale session token is the usual culprit, and a fresh one fixes it. 5: Add an exception for sites you trust that break under blocking. Chrome's "Allowed to use third-party cookies" list and Firefox's "Manage Exceptions" dialog both accept specific domains. 6: Check for "clear cookies and site data when you close all windows," an option in Chrome and Firefox. If it's on, persistent cookies won't survive restarts, and every site forgets you. That setting explains most "why am I logged out every morning" complaints.

If a site breaks after blocking, the failure-handling move is per-site allowance, not disabling protection globally. Banking portals, SSO providers, and payment flows often depend on third-party cookies because the payment processor sits on a different domain. Allow those domains and leave the rest blocked. The default browser protections, including Safari's Intelligent Tracking Prevention and Firefox's Total Cookie Protection, already limit third-party tracking, so a heavy-handed extension is rarely necessary on top.

One measurement worth doing yourself: count the cookies a site sets before you touch anything. Chrome's DevTools (Application β†’ Storage β†’ Cookies) lists them by domain and flag, and the count is often surprising. A news homepage routinely sets a dozen or more across several domains. That number tells you more about a site's tracking posture than any banner text.

The Cookie's Origin Story and the 1994 Problem It Solved

The cookie was invented to solve a specific technical problem: HTTP is stateless. Every request is independent, and the server has no memory of the last one. In 1994, Lou Montulli, an engineer at Netscape, designed a small token the browser would store and return so a server could recognize a returning client. Netscape's documentation described the mechanism as a "cookie," and the name stuck. It was a pragmatic fix, not a surveillance design.

The early use case was a shopping cart that survived navigation between pages. That's still the canonical example, and it explains why the mechanism has endured. Any protocol that forgets everything between requests needs a way to say "it's still me," and cookies are the least invasive way to do that. According to the World Wide Web Consortium, the mechanism was standardized through RFC 2109 in 1997 and refined by RFC 2965 before RFC 6265 in 2011 settled on the model browsers implement today.

Tracking arrived later as a side effect, not a feature. Advertisers realized that a third-party cookie on a popular site could follow a user across the web, and a whole industry formed around that possibility. The backlash followed. Browsers began blocking third-party cookies by default, regulators wrote consent rules, and Google announced plans to phase out third-party cookies in Chrome, later revising that plan to offer users a choice rather than removing them outright. The mechanism survived; the tracking layer has been squeezed.

The origin matters for one practical reason. Because cookies were designed for server-side state, features built on them assume that a small identifier will arrive with each request. That assumption is baked into countless frameworks, login systems, and e-commerce platforms. A future without cookies wouldn't just remove tracking; it would require rewriting how the web remembers people. That's why the cookie has outlasted repeated predictions of its death.

What Actually Changes When You Accept or Reject a Banner

Accepting a consent banner usually sets a cookie recording your choice, plus the analytics and advertising cookies the site wants to load. Rejecting it sets a cookie recording the rejection, and ideally loads nothing else. Both outcomes involve a cookie, which surprises people who assume rejection means zero cookies. The consent record itself is typically categorized as strictly necessary, so it can be set without permission.

The difference shows up in what loads next. A rejected banner usually stops third-party scripts from firing, which means no ad network cookie, no cross-site identifier, and faster page loads. A page with heavy advertising scripts can easily outweigh the article it displays. That load-time cost is the most tangible benefit of rejecting, and it's the one you can feel without any tool.

The harder problem is dark patterns. A banner that makes "Accept all" a large button and "Reject" a small gray link below the fold is designed to inflate acceptance, and regulators have started to catch it. According to guidance from the European Data Protection Board, consent requires an affirmative action, and pre-ticked boxes or implied consent don't qualify. The EDPB is the body coordinating EU data-protection enforcement, so its guidance shapes how national regulators act. A banner that ignores it risks complaint.

What a rejection doesn't do is stop first-party analytics entirely. A site can still log your visit server-side without a cookie, using your IP address and request headers. Consent rules generally cover device storage and access, so server-side logging sits in a different legal category. That distinction is why privacy-conscious visitors sometimes reject every banner and still see relevant ads: the ad was targeted by other means. The cookie is one instrument in a larger arrangement.

How Cookies Compare With Fingerprinting and Server-Side Tracking

The cookie is the visible layer of a stack that extends further than most people realize. Fingerprinting combines browser properties, such as screen size, installed fonts, and rendering quirks, into a probabilistic identifier that survives cookie clearing. Server-side tracking logs requests on the server and links them by IP address, timestamp, and account. Both approaches exist because cookies are easy to block, and blocking changed the economics of measurement.

The comparison below puts the three side by side on the dimensions that matter to a visitor deciding what to control.

Method Survives cookie clearing Visible in browser settings Consent typically required in the EU Practical control available to a visitor
First-party cookie No Yes Only for non-essential uses Delete per site; allow exceptions
Third-party cookie No Yes Yes for analytics and ads Block category-wide in browsers
Browser fingerprint Often yes Partially Yes, under ePrivacy read-access rules Limit via browser hardening; no single switch
Server-side logging Not applicable No Depends on purpose and legal basis Limited; contact the site or use a VPN

The fourth row is the uncomfortable one. Server-side logging isn't storage on your device, so the ePrivacy consent rule doesn't apply the same way. Whether it's lawful depends on purpose, legal basis, and jurisdiction, which is why data-protection authorities publish guidance rather than a single switch. For a visitor, the realistic control is choosing which sites to visit and using a reputable tracker-blocking extension, not flipping one browser setting.

Fingerprinting earns its reputation for a reason. Research published by the Electronic Frontier Foundation's Panopticlick project, later renamed Cover Your Tracks, found that a large share of browsers could be identified uniquely from their configuration alone. The exact share varies by sample and date; the EFF's test page reports your own result, which is the figure worth trusting over any cited percentage. That finding is why "just clear your cookies" is incomplete advice.

This is a general explanation of how web tracking works and not legal advice. Rules differ by country and change over time. Consult a qualified local professional for compliance questions about your own site, and check the guidance from your national data-protection authority for current requirements.

FAQ

Do cookies contain personal information like my name?

Usually not directly. Most cookies hold a random identifier or a preference value, and the personal data sits on the server linked to that identifier. A cookie can contain a name if a site chooses to write one, which is poor practice. Treat any cookie holding directly identifying data as a sign of weak design.

No. A cookie is a text file with no executable content, so it cannot run code, install software, or replicate. The realistic risk is theft of a session cookie, which lets an attacker act as you until the session expires. That risk is why HttpOnly and Secure flags matter and why logging out matters on shared devices.

Why am I logged out every time I close my browser?

Check two settings before blaming the site. First, your browser may have "clear cookies and site data when you close all windows" enabled. Second, the site may set only session cookies with no expiry, which is a deliberate security choice for banking and email. If both are fine, the site's cookie may be failing its domain or size check.

Are cookies the same as spyware?

They're different categories. Spyware is software installed on a device that collects data covertly. A cookie is a data file set by a website within browser sandbox rules, visible in settings, and deletable. Some cookies support tracking that people find invasive, but the mechanism itself isn't spyware and doesn't install anything.

How many cookies does a typical website set?

It varies widely, and the honest answer is to count. Open DevTools, go to Application, then Cookies, and read the list by domain. A news homepage often sets more than a dozen across several domains, while a simple documentation site may set two. The count and the domains tell you more than any general figure.

Do I need to accept cookies to use a website?

Only for cookies that are strictly necessary, such as login sessions and security tokens. In the EU and UK, non-essential cookies require consent, so you can reject them and keep using the site. Sites that lock content behind "accept all" are testing the rules, and you can complain to your national regulator.

What happens to my cart if I clear cookies?

It usually empties, because the cart contents are tied to a session identifier stored in a cookie. Some stores persist carts to your account if you're logged in, in which case clearing cookies and signing back in restores the cart. If you're a guest, the cart is gone, and that's the mechanism doing its job.

No. A cache stores copies of files like images, scripts, and stylesheets so pages load faster. A cookie stores a small piece of state tied to a domain. Clearing your cache fixes stale page rendering, while clearing cookies fixes login and preference problems. The two menus sit near each other in browser settings, which is why they get confused.