Technology & Computing · Digital life & society

How cookies let websites remember and track you

A cookie is a small note a server asks your browser to keep and hand back. See why the web needs them, how one company can use them to follow you across sites, and what browsers do about it.

4 short lessons · about 25 minutes · 5 sources · updated November 2026

A courier carrying one cookie from a house to a large building, and the same courier bent under a tall stack of cookies.

What you will learn

  • Explain what a cookie is and why a stateless protocol needs one
  • Choose between a session cookie, a permanent cookie and a storage API
  • Decide whether a cookie is first party or third party for a given page
  • Give the common legitimate reasons a third-party cookie is set

Lesson 1 of 4 · 6 min

What a cookie is and why the web needs one

Before you readIn 1994 an online shop needed a cart, but its client didn't want its servers tracking half-finished orders. Where did the programmer put that information?

Correct.Not quite. The answer is On the shopper's own computer.

The shopper's own browser holds it, as a small piece of data called a cookie. This lesson shows why the web needs one.

In June 1994, the browser company Netscape was building an online shop for a client, and the shop needed a cart. The client didn't want its servers keeping track of every half-finished order. So a Netscape programmer, Lou Montulli, had the shopper's own computer hold that information.

The problem he was solving is still there. HTTP, the protocol that carries web pages, is stateless. Each request arrives with no memory of the one before. Montulli's fix was a small piece of data that the server hands to the browser, and that the browser sends back with later requests. He called it a cookie, after programmers' slang for data a program receives and returns unchanged.

Signing in shows the whole mechanism. You send your username and password. If they're right, the server replies with a cookie holding a session ID. On the next page, your browser sends that cookie along. The server checks the ID, and if it's still valid, you get your own version of the page. If it isn't, you're asked to sign in again.

Cookies have three main jobs. Session management covers sign-ins and shopping carts. Personalization covers preferences such as language and theme. Tracking means recording and analyzing what users do. The first two are why cookies exist. The third is why you've heard of them.

Check yourselfA web page loads over HTTP, the request finishes, and the next request arrives with no memory of the first. What does a cookie add?

Correct.Not quite. The answer is A small value the browser keeps and sends back, so the server can recognize the browser later.

HTTP is stateless by default, so nothing in the second request links it to the first. The server sends a value, the browser keeps it and returns it with later requests to the same server, and that returned value is what lets the server recognize the session. Keeping a connection open and storing built pages are different mechanisms that solve different problems.

A cookie is tiny. A whole one can be as short as theme=dark, a name and a value. Whoever sets it also decides how long it lasts.

A permanent cookie carries an expiry, either a date or a lifetime in seconds called Max-Age. Max-Age is the less error-prone choice, because a date is read against the clock of the user's device, which may not agree with the server's.

A cookie with no expiry is a session cookie, deleted when the session ends. The catch is that the browser decides when that is. Some browsers restore your session when they restart, so a session cookie can last indefinitely. To delete a cookie at once, the server sets it again with a lifetime of zero.

Some sites use techniques that recreate cookies after you delete them. These zombie cookies violate the principle of user control and may break privacy law.

Cookies were once the only way to store data in a browser, and they're now the wrong tool for it. Browsers cap each one at about four kilobytes and allow a few hundred per domain. Worse, every cookie is sent with every request, so a pile of them slows each page load. Newer browser storage, such as localStorage and IndexedDB, holds more and never sends anything to the server.

Try to recallAn application wants to keep a long list of user interface preferences that the server never reads. Why is a cookie a poor place to keep them, and what should the application use instead?

A cookie is small and it travels constantly. Browsers cap each cookie at about four kilobytes and allow only a few hundred per domain, so a long list may not fit. And every cookie is sent with every request to that server, so data the server never reads gets uploaded again and again, slowing each page load.

The right place is browser storage built for the job, such as localStorage or IndexedDB. It holds more, and it never sends anything to the server.

So a cookie is a short note that a server asks your browser to keep and hand back. It was invented so a shop could remember your cart, and it still does that job. What turned it into a privacy problem is the matter of which server gets the note back. A cookie can belong to the site you're visiting or to a different one, and that difference decides what it can be used for.

Lessons in this topic

  1. What a cookie is and why the web needs one

    The web's basic protocol forgets you between one request and the next. See how a cookie works around that, how long one lasts and what it's the wrong tool for.

    Essentials · 6 min

  2. What makes a cookie first party or third party

    The label depends on one comparison with the address bar, and who owns the sites doesn't come into it. See the ordinary jobs third-party cookies do.

    Essentials · 6 min

  3. How a tracking cookie follows you from site to site

    One embedded company sees a little of you on every site that carries its content. See how that adds up to a profile, and what each major browser does about it.

    Deeper · 6 min

  4. The five settings that decide where a cookie goes

    SameSite, Secure, HttpOnly, Domain and Path control where a cookie travels and who can read it. Two of them protect less than their names suggest.

    Deeper · 7 min

Three quick stories from this topic

The rule browsers ignored

The first cookie standard, in 1997, told browsers to block third-party cookies by default

Its authors had already identified cross-site cookies as a privacy threat. Netscape and Internet Explorer didn't follow the rule, and advertisers were using such cookies by then. As of 2026, Chrome still allows them by default.

What third party means

A cookie is third party when its site differs from the one in your address bar. Ownership doesn't matter, so a company's second domain sets third-party cookies on the company's own pages.

What other browsers do

Firefox gives every site a separate cookie jar by default, Safari has similar protections and Brave blocks tracking cookies, according to Mozilla's 2026 documentation.

Google's $22.5 million cookie

Google agreed to pay $22.5 million in 2012 over a tracking cookie Safari was set to block

Safari blocked third-party cookies by default, and Google had told Safari users that this kept them opted out of its ad tracking. The US Federal Trade Commission charged that Google used an exception in the setting to place the cookie anyway. Google settled without admitting liability.

How a tracking cookie works

A company whose content is embedded on many sites gets its own cookie back from your browser on each one. Combined, those visits form a profile of your browsing.

Why browsers can't just filter them

A tracking cookie is technically indistinguishable from a useful one, such as a shared sign-in. So browsers block or separate third-party cookies wholesale.

Why the cookie was invented

The cookie was invented in 1994 so an online shop could keep your cart on your computer

Netscape programmer Lou Montulli devised it for a client that didn't want its servers tracking half-finished orders. Browsers accepted cookies without notifying anyone. The public learned about them in February 1996, from an article in the Financial Times.

The problem it solved

HTTP, the protocol that carries web pages, keeps no memory between one request and the next. A cookie is a small value the server asks the browser to keep and send back.

Where the name comes from

Montulli took it from 'magic cookie,' a term Unix programmers used for a packet of data that a program receives and sends back unchanged.

Sources

This topic is part of Why computers don't do what you'd expect, a guided path through related topics.

  • How recommendation feeds decide what you see

    Follow how a feed narrows billions of items to a screenful, what its score rewards, and how the design of a screen steers the choices you make.

    4 lessons · 17 min

  • Social media

    See how social networks grew from friend lists into feeds of strangers' videos, why they cost nothing to use, why the leading app differs by country, and what experiments say about their effect on politics.

    4 lessons · 16 min

  • Online advertising and free services

    Search, maps and social apps cost nothing because advertisers pay for your attention. See how one ad slot is auctioned while a page loads, how ads get targeted and measured, and where fraud and blockers bite.

    4 lessons · 16 min

  • How a database keeps records consistent

    See how transactions, built-in rules and isolation levels keep records right when a server crashes, two buyers want one seat or two updates collide.

    4 lessons · 17 min

  • How processors execute instructions

    Follow a tiny calculation through the instructions, memory addresses and circuits that make a computer work.

    4 lessons · 22 min

  • Wi-Fi and home networks

    See how your router sends data on radio waves, why walls and neighbors slow it down, how one internet address serves every device at home, and where Bluetooth and mobile data fit.

    4 lessons · 18 min

All technology & computing topics · Take the quiz