Technology and Gadgets · Internet and the web
What Are Internet Cookies? How They Work and How to Control Them
The short answer
Internet cookies are small bits of text a website asks your browser to store and send back on later visits. They keep you logged in, remember your cart and settings, and measure visits. Third-party cookies, set by ad and analytics companies embedded in pages, can also follow you across many sites [1][2].
What is an internet cookie, in plain terms?
A cookie is a tiny note a website leaves with your browser. When you visit a site, its server can send a line of text along with the page, asking your browser to keep it. The next time your browser asks that same site for anything, it hands the note back. That's all a cookie is: a name, a value and a few instructions about where and how long it applies [1].
Why does the web need this? On its own, a web server treats every request as a stranger. Cookies give it a short memory, so it can tell that the person loading page two is the same one who just signed in on page one. The official standard describes cookies exactly this way: a way for servers to store "state" in your browser [1].
Here's what that exchange looks like behind the scenes, using the example from the standard itself [1]:
- You sign in. The server replies with a header such as
Set-Cookie: SID=31d4d96e407aad42, a random session ID. - Your browser stores it, filed under that site's address.
- On every later request to the site, your browser adds
Cookie: SID=31d4d96e407aad42. - The server looks up that ID and knows it's you, so you stay signed in.
Notice what's in the cookie: just a random-looking label. Your name and password usually stay on the server; the cookie is the claim ticket that points to them.
What are cookies actually used for?
The FTC lists the everyday jobs cookies do: saving your preferences and information, like your username or what you left in your shopping cart; showing personalized content such as local weather; gathering analytics about your visit; and remembering what you searched for [2]. Put simply, most of the convenience you take for granted online, such as staying logged in to email or coming back to a full cart, runs on cookies.
The other big use is advertising. Websites may use a cookie to identify you even after you leave the site [2], which is how an ad for the shoes you looked at yesterday turns up on a news site today.
What's the difference between session, persistent and third-party cookies?
Cookies are sorted in two ways: how long they last, and who sets them.
| Type | How it works | Typical use |
|---|---|---|
| Session cookie | Has no expiration date, so the browser drops it when your browsing session ends [1][3] | Keeping you signed in while you click around, holding a checkout in progress |
| Persistent cookie | Carries an expiration date and survives closing the browser until then [1] | "Remember me" logins, language and display settings, saved carts |
| First-party cookie | Set by the site shown in your address bar | Logins, preferences, the site's own analytics |
| Third-party cookie | Set by another company whose content is embedded in the page, such as an ad network [1] | Ad targeting and measuring ads across many sites |
How long can a persistent cookie last? A site can ask for any date, but browsers set limits. Since Chrome 104 (August 2022), Chrome caps cookie lifetimes at 400 days from when the cookie was set; a site that wants to keep you longer has to renew the cookie when you come back [3]. Cookies can also vanish sooner, for example because you clear them or a site goes over the browser's per-domain cookie limit [3].
How do third-party cookies track you across websites?
When a page loads, your browser often fetches pieces from other companies: ads, share buttons, analytics scripts. Each of those companies can set and read its own cookie. The standard spells out the result: if you visit one site containing content from a third party, then later visit another site containing content from that same third party, the third party can track you between the two, even if you never visit it directly [1].
Multiply that by the thousands of sites using the same ad networks and you get the cross-site profile behind targeted ads. The FTC puts it plainly: third-party tracking companies can track you across most websites you visit [2]. If you want the related trick that works even in email, see our guide to web bugs and tracking pixels.
Do browsers block third-party cookies now?
Some do by default, and the big three differ:
| Browser | Default approach |
|---|---|
| Safari | Has blocked cookies for cross-site resources by default since Safari 13.1 and iOS 13.4 (March 2020) [4] |
| Firefox | Total Cookie Protection gives each website its own separate "cookie jar", so a tracker's cookie on one site can't be read on another [5] |
| Chrome | Dropped its plan to phase out third-party cookies; you choose in Privacy and Security settings. Incognito blocks them by default [6] |
One thing worth knowing: for years Google said Chrome would phase out third-party cookies. In April 2025 it announced it would keep its current approach of letting users choose, and would not roll out a new standalone prompt [6]. So in Chrome, blocking is up to you.
How do you delete or block cookies?
The cookie standard says browsers should let you view, delete and disable cookies [1], and every major browser does, usually under Settings, then Privacy (or Privacy and Security). A sensible routine:
- Block third-party cookies. This cuts a lot of cross-site ad tracking, and most ordinary sites keep working.
- Delete cookies when you want a fresh start. The FTC suggests deleting cookies and clearing your browsing and search history if you don't want ads based on past activity [2]. Expect to be signed out of sites afterward.
- Delete one site at a time when needed. Many browsers let you remove the cookies for a single domain [1], handy when one site misbehaves and you don't want to log out everywhere.
- Use the cookie banner's choices. Many let you allow only necessary cookies [2].
- Consider an ad blocker. Some block pixels and other trackers too [2]. Our guide on how to choose an ad blocker covers the options.
Blocking all cookies is possible, but expect logins, carts and many sites to stop working, since they rely on cookies to remember you from one page to the next.
Cookie myths, checked
| Myth | Reality |
|---|---|
| Cookies are programs that can infect your computer | They're short text stored and returned by your browser [1]; they don't run code |
| Cookies are always encrypted | Not by default. Over a plain HTTP connection, cookies travel in the clear; the standard asks sites to encrypt and sign cookie contents and use secure connections [1] |
| Any site can read all your cookies | A browser sends a cookie back only to the site (domain and path) it belongs to [1] |
| Blocking cookies makes you invisible | Sites can still use fingerprinting, pixels and your IP address [2] |
| Incognito mode hides what you do | It deletes your browsing history when you end the session, but websites can still see your activity [2] |
For more on what your connection reveals, see whether websites track IP addresses.
Do US laws regulate cookies?
In the US, privacy rules that touch cookies come largely from state laws, and California's is the best-known example. Under the California Consumer Privacy Act, consumers can ask businesses to stop selling or sharing their personal information, and "sharing" specifically means sharing for cross-context behavioral advertising, which is ads based on your activity across many websites [7]. That's largely the third-party cookie business.
California also accepts the Global Privacy Control (GPC), a browser setting that acts as a "stop selling or sharing my data" switch. The Attorney General's office notes it's available in some browsers, like Firefox, DuckDuckGo and Brave, and that covered businesses must honor it as a valid opt-out request [7]. If you'd like to use a privacy law, check your own state's attorney general website, or ask a lawyer for anything beyond the basics.
For the curious: the technical details
Cookies started life as a Netscape proposal. The first standards-track specification, RFC 2109, came out in February 1997, co-written by Netscape's Lou Montulli, and noted that it differed from Netscape's original cookie proposal while staying compatible with it [8]. Today's rules are in RFC 6265 (April 2011) [1].
A few attributes do most of the work [1]:
- Expires / Max-Age: make a cookie persistent. Without them, it's a session cookie.
- Domain and Path: decide which addresses get the cookie back.
- Secure: the cookie is only sent over encrypted (HTTPS) connections.
- HttpOnly: page scripts can't read the cookie, which makes login cookies harder to steal.
Browsers have storage limits too. The standard asks them to support at least 4,096 bytes per cookie, 50 cookies per domain and 3,000 cookies in total [1]. About 4 KB is only a page or so of plain text, which is one reason sites usually store an ID in the cookie and keep the real data on their servers. Cookies are also different from your browser's web cache, which stores copies of pages and images to load them faster.
Frequently asked questions
Are internet cookies dangerous or can they carry viruses?
A cookie is a short piece of text, not a program, so it can't run on your computer or install anything. The real risks are privacy (tracking across sites) and security: if someone steals a login cookie, they may be able to act as you on that site. That's why the cookie standard tells sites to protect sensitive cookies and send them only over secure connections [1].
Should I accept cookies when a website asks?
It depends on what you're comfortable with. The FTC notes that many cookie notices let you allow only the cookies a site needs to work, or also allow advertising and other cookies, and suggests choosing the option that fits your preferences [2]. Turning down non-essential cookies usually doesn't stop a site from working.
Does private or incognito mode stop cookies?
Partly. Private browsing deletes your browsing history when you end the session, but the FTC points out that private browsing doesn't stop websites from seeing what you do while you're there [2]. Chrome's Incognito mode also blocks third-party cookies by default [6].
Will deleting cookies log me out of websites?
Yes, usually. Staying signed in depends on a cookie holding your session, so clearing cookies signs you out and resets saved preferences such as language or cart contents. Most browsers let you delete cookies for a single site if you'd rather keep the rest [1].
If I block cookies, can websites still track me?
Yes, to some degree. The FTC warns that sites can use device fingerprinting, which identifies you from your browser's unique configuration and settings, and tracking pixels [2]. The cookie standard itself notes that two cooperating servers can often track users without cookies, for example by putting identifiers in links [1].
Sources
- RFC 6265: HTTP State Management Mechanism. Internet Engineering Task Force (IETF)
- How Websites and Apps Collect and Use Your Information. Federal Trade Commission, Consumer Advice
- Cookie Expires and Max-Age attributes now have upper limit. Google, Chrome for Developers
- Full Third-Party Cookie Blocking and More. WebKit (Apple)
- Firefox rolls out Total Cookie Protection by default to more users worldwide. Mozilla
- Next steps for Privacy Sandbox and tracking protections in Chrome. Google, Privacy Sandbox
- California Consumer Privacy Act (CCPA). State of California, Department of Justice, Office of the Attorney General
- RFC 2109: HTTP State Management Mechanism. Internet Engineering Task Force (IETF)