Quick answer
A cookie on a website is a small piece of text (name and value) that the site asks your browser to store with a Set-Cookie header and that the browser sends back in a Cookie header on later requests, so the site can remember logins, carts, preferences or a returning browser.
What is a cookie on a website?
A cookie (HTTP cookie) is a small piece of text that a website asks your browser to store and then send back to the same site on later requests. The site sets it with a Set-Cookie response header; the browser returns it in a Cookie request header. That round trip lets a stateless protocol remember things between page loads: that you are logged in, what is in your cart, which language you picked, or that this browser has visited before.
A cookie is data, not a program. It cannot run code, read your files or install anything. What makes cookies matter for privacy is not what they are, but who sets them, how long they last and what the identifier inside them is used for. The mechanism is defined in RFC 6265 (IETF, April 2011), and every browser implements the same basic exchange.
How does a cookie work?
The exchange has two steps.
- The server sets it. In its response, the server includes a header such as:
Set-Cookie: cart_id=7f3a9c21; Max-Age=2592000; Path=/; Secure; HttpOnly; SameSite=Lax
- The browser sends it back. On every later request to a matching host and path, until the cookie expires, the browser adds:
Cookie: cart_id=7f3a9c21
Only the name and value travel back; the attributes stay in the browser and decide when the cookie is sent. In the example, Max-Age=2592000 is 2,592,000 seconds, which is 30 days (2,592,000 ÷ 86,400). The whole header line is 85 characters, far below the size limit.
RFC 6265 section 6.1 sets the minimum a general-purpose browser should support: at least 4,096 bytes per cookie (name, value and attributes together), at least 50 cookies per domain and at least 3,000 cookies in total. Sites that store more than a short ID usually hit problems on the first limit, because cookies are sent with every request and large ones slow every page and image load.
Cookie attributes explained
| Attribute | Example | What it does | If you leave it out |
|---|---|---|---|
Expires | Expires=Wed, 30 Dec 2026 08:00:00 GMT | Sets an end date for the cookie | Cookie is a session cookie |
Max-Age | Max-Age=2592000 | Lifetime in seconds; wins over Expires if both are set | Falls back to Expires, then session |
Domain | Domain=example.com | Sends the cookie to that domain and all its subdomains | Sent only to the exact host that set it |
Path | Path=/account | Sends the cookie only for URLs under that path | Defaults to the path of the request URL |
Secure | Secure | Sends the cookie only over HTTPS | Sent over HTTP too |
HttpOnly | HttpOnly | Hides the cookie from JavaScript (document.cookie) | Scripts on the page can read it |
SameSite | SameSite=Lax | Strict: same-site requests only; Lax: also top-level navigations from other sites; None: all requests, and requires Secure | Some browsers apply Lax |
Partitioned | Partitioned | Stores a separate copy per top-level site; requires Secure | One shared copy |
Two practical rules follow from the table. A login or cart cookie should carry Secure, HttpOnly and SameSite=Lax or Strict unless there is a specific reason not to. And Domain widens scope rather than narrowing it: omit it if only one host needs the cookie. MDN also documents the __Host- prefix, which forces Secure, Path=/ and no Domain, so a subdomain cannot overwrite the cookie.
Session vs persistent cookies
The lifetime split depends only on whether Expires or Max-Age is present.
| Session cookie | Persistent cookie | |
|---|---|---|
| How it is set | No Expires or Max-Age | Expires or Max-Age present |
| When it is deleted | When the browser session ends (the browser decides when that is) | At the expiry time, or when the user clears it |
| Typical use | Login state for one visit, checkout steps | "Remember me", language choice, analytics or ad identifiers |
| Example | Set-Cookie: sid=a1b2 | Set-Cookie: lang=de; Max-Age=31536000 |
"Session" refers to the browser session, not to an analytics session. Browsers that restore tabs on restart may keep session cookies much longer than people expect, so do not rely on a session cookie to log someone out.
First-party vs third-party cookies
Who sets a cookie matters more for privacy than how long it lasts. A first-party cookie belongs to the site in the address bar: shop.example sets cart_id and reads it back on its own pages. A third-party cookie belongs to another domain whose resource is embedded on the page, such as an ad or social widget at tracker.example. Because that domain is embedded on many sites, its cookie can link one browser's visits across all of them.
| Cookie | Set by | Can it follow you across sites? | Typical consent position in the EU |
|---|---|---|---|
| First-party, strictly necessary (cart, login, load balancing) | The site you visit | No | Exempt from consent |
| First-party, preferences (language, theme) | The site you visit | No | Usually exempt if the user asked for the feature |
| First-party, analytics | The site, via an analytics script | No | Needs consent in most EU countries |
| Third-party, advertising or tracking | An embedded domain | Yes | Needs consent |
Which cookies need consent?
In the EU and EEA the rule comes from Article 5(3) of the ePrivacy Directive (2002/58/EC, rewritten by Directive 2009/136/EC). Storing information on a user's device, or reading information already stored there, needs the user's consent after clear and comprehensive information. There are two exemptions: storage needed only to transmit a communication, and storage strictly necessary to provide a service the user explicitly asked for.
A decision rule you can apply to each cookie on your site:
- Would the feature the user requested break without it? A cart cookie on a shop or a session cookie after login: exempt.
- Does it remember a choice the user made? A language cookie set when they picked a language: usually exempt.
- Is it for measurement, advertising, personalization the user did not ask for, or cross-site tracking? It needs consent before it is set.
Article 5(3) is about storage and access on the device, not about the word "cookie". Local storage, pixels that read stored IDs and device fingerprinting fall under the same rule, which is why "we use local storage instead" does not remove the consent question. When the cookie data identifies a person, the GDPR applies on top. Outside the EU, rules differ by country and state. This page is a definition, not legal advice.
Cookies vs local storage and other browser storage
Cookies are often confused with other ways a site can keep data in the browser.
| Cookie | localStorage | sessionStorage | |
|---|---|---|---|
| Sent to the server automatically | Yes, with every matching request | No | No |
| Size | About 4 KB each (RFC minimum) | Several MB per origin | Several MB per origin |
| Readable by JavaScript | Yes, unless HttpOnly | Yes | Yes |
| Lifetime | Session or until expiry | Until cleared | Until the tab closes |
| Can be set by the server | Yes, via Set-Cookie | No | No |
The practical difference: only cookies reach the server without extra code, which is what makes them useful for logins and also what makes them a tracking vehicle. Cookieless analytics avoids both cookies and these stores, and counts visitors by other means.
How to see the cookies a site sets
- Open the site in a fresh private window so old cookies do not mix in.
- Open developer tools and go to Application (Chrome, Edge) or Storage (Firefox), then Cookies, and select the site.
- Read each row: name, domain, expiry, size and the
HttpOnly,SecureandSameSiteflags. A domain that differs from the address bar is a third-party cookie. - In the Network tab, click the first document request and look for
Set-Cookiein the response headers, to see which cookies the server sets before any script runs. - Reject non-essential cookies in the banner, reload, and check that only strictly necessary ones remain.
Common mistakes
- Setting analytics cookies before consent. In the EU the banner must come first; loading the script and asking afterwards defeats the purpose.
- Treating a long
Max-Ageas harmless. A cart cookie that lives 10 years outlives the cart; keep lifetimes close to the purpose. - Storing personal data in the value. Put an opaque ID in the cookie and keep the email or name on the server.
- Forgetting
SecureandHttpOnlyon login cookies, which exposes them to network sniffing and script injection.
How TapCub counts visitors without cookies
Take a site that wants traffic numbers but does not want an analytics cookie in its cookie list. In TapCub that is the default:
- Install the website script. In the default anonymous mode, the script writes neither a cookie nor local storage. You can confirm it with the inspection steps above: no TapCub entry appears under Cookies.
- Visitors are still separated. The collector derives a visitor ID from a salted hash of the address and browser data, then discards the address. In the default balanced preset the salt is site-level, so returning visitors can be compared; the strict preset rotates the salt daily. See how cookieless counting works.
- Set region rules in Configuration › Privacy center. The default rule for the EEA and the UK is collection tier 2 with consent required. Without analytics consent, hits drop to tier 1 (anonymous aggregate), and pageviews and custom events are still recorded.
- Turn on identification only if you need it. Identified mode writes a device ID once consent is granted and the tier is 3. Whether your site needs a banner depends on your configuration and local law; see do I need a consent banner.
TapCub does not manage your other cookies or run a consent banner; it only measures, within the tier the visitor's consent allows.
Sources
- IETF, RFC 6265: HTTP State Management Mechanism (April 2011), sections 4.1, 5.3 and 6.1.
- MDN Web Docs, Set-Cookie header.
- EUR-Lex, Directive 2002/58/EC (ePrivacy Directive), Article 5(3).
- EUR-Lex, Directive 2009/136/EC, which rewrote Article 5(3) to require consent.
Was this explanation clear?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.

Data Analyst
Explores traffic sources, conversion funnels, and retention, using clear metric definitions and concrete examples to explain what the numbers mean.