Cookies explained in plain terms means understanding the small files that websites store in your browser, so they can remember you when you return. The central question is how a website knows it is you, and not a stranger, when you come back a week later, and the short answer is that it left a cookie on your device, a tiny note with an identifier, and your browser hands it back on the next visit.
You meet cookies on almost every site you visit. They keep you logged in, remember what is in your shopping basket, and save your language and display preferences, so you do not have to set them again each time. Without them, every page you loaded would treat you as a brand-new visitor.
Cookies also carry a reputation problem, because the same mechanism that remembers your login can be used to follow you across the web. Advertising networks use cookies to build a picture of your interests, and that tracking is the reason cookie banners appear on nearly every site in Europe, asking for your consent before they are set.
Key takeaways
- A cookie is a small file a website stores in your browser, containing an identifier or a preference.
- First-party cookies come from the site you are visiting and usually make it work better; third-party cookies come from other domains, often for advertising.
- Cookies remember logins, shopping baskets, and settings, because the web itself has no memory of past visits.
- They can also track you across sites, which is why privacy laws require consent for non-essential cookies.
- You can view, block, and delete cookies in your browser settings, though blocking them all can break sites.
What cookies are
A cookie is a small piece of data, usually no more than a few hundred characters, that a website asks your browser to store. It contains a name, a value, and rules about where it applies and when it expires. The value is often a random identifier, a long string that means nothing on its own but lets the site recognise the same browser later.
The web was designed without memory: each request a browser makes is independent, and the server forgets you the moment it answers. Cookies were invented to fill that gap, giving the server a way to recognise a returning visitor. When you log in, the server sets a cookie with your session identifier, and on every later page your browser sends that identifier back, so the server knows you are still logged in.
Not all cookies do the same job. Strictly necessary cookies keep the site working, such as the one that holds your login or your basket. Preference cookies remember settings such as language or region. Analytics cookies count visitors and measure which pages are popular. Marketing cookies follow you across sites to build an advertising profile, and these are the ones that attract the most attention from privacy regulators.
The distinction that matters most is first-party versus third-party. A first-party cookie is set by the domain in your address bar, while a third-party cookie is set by another domain whose content is embedded in the page, such as an advert or a social media button. Our guide to data privacy explains the wider rules that govern personal data, and our guide to TLS explains how the connection itself is encrypted while cookies travel over it.
How cookies work
When a server wants to set a cookie, it includes a header in its reply that tells the browser the cookie’s name, value, and rules. The browser stores it, and on every later request to a matching address it includes the cookie in a header of its own, so the server receives it without asking again. The exchange is automatic and invisible, happening on every page you load.
Each cookie carries rules that limit where it applies. The domain rule says which sites receive it, the path rule says which pages, and the expiry says how long it lives: a session cookie is deleted when you close the browser, while a persistent cookie can last for months or years. Secure and HttpOnly flags add protection, with the first requiring an encrypted connection and the second keeping the cookie out of reach of scripts on the page.
Third-party tracking uses the same mechanism across many sites. An advertising network’s code is embedded in thousands of pages, and each one sets or reads the network’s cookie, so the network learns which sites the same browser visited. Over time that browsing history is used to infer interests, and adverts are chosen to match. Blocking third-party cookies breaks that chain, which is why browsers have begun to restrict them by default.
Cookie banners exist because the law changed the rules. In the European Union and the United Kingdom, a site must get your consent before setting cookies that are not strictly necessary, and it must explain what each kind does. That is why you are asked to accept or reject cookies on nearly every site, and why rejecting them should still let you use the site, even if some features work less smoothly.

Comparing cookie types
Cookies differ by who sets them, how long they last, and what they are for. The necessary ones make sites work, while the tracking ones fund free content and raise the privacy questions that dominate the debate.
The table below sets out the main contrasts.
| Aspect | Strictly necessary | Preference | Analytics | Marketing |
|---|---|---|---|---|
| Set by | The site you visit | The site you visit | The site or its analytics tool | An advertising network |
| Purpose | Login, basket, security | Language, region, display | Counting visitors, popular pages | Tracking interests for adverts |
| Consent needed | No, exempt in most laws | Usually yes | Usually yes | Yes |
| Typical life | Session, or a few days | Months | Months | Months to years |
| If blocked | Site may not work | Settings reset each visit | Site still works | Adverts less personal |
The rule of thumb is simple: accept the necessary ones, decide the rest for yourself. A site that stops working when you reject marketing cookies is doing something wrong, and a browser that blocks third-party cookies by default is protecting you without breaking the sites you use.
Where cookies are used
Shopping is the most familiar use. A basket that survives from one page to the next, a login that stays active while you browse, and a checkout that remembers your address are all cookies at work. Without them, an online shop would forget you between every click, and buying anything would be impossible.
Advertising is the largest use by volume. Networks place cookies through adverts and tracking pixels on millions of sites, building profiles that decide which advert you see. That system pays for much of the free content on the web, from news to video, which is why the debate about cookies is really a debate about how the web is funded.
Analytics is a quieter use. Site owners count visitors, learn which pages are popular, and find where people give up, using cookies to tell new visitors from returning ones. That measurement shapes what gets written, fixed, and promoted, and most sites would be flying blind without it.
Security uses cookies too. A session cookie proves you are logged in, a security cookie can flag a login from an unfamiliar device, and some cookies store a token that protects forms against forgery. These are the cookies that make the web usable and safe at the same time, and they are the reason blocking every cookie breaks sites.
Strengths and limits
The greatest strength of cookies is that they give the web a memory. Without them, every request would start from nothing, logins would not last beyond a page, and baskets would empty themselves. A small, simple mechanism supports almost everything people expect a website to do.
They are also lightweight and widely supported. Every browser understands them, they cost almost nothing to use, and they work the same way on a phone, a laptop, and a television. That universality is why they have survived three decades of change on the web.
The limits are about privacy and trust. A cookie is only as honest as the site that sets it, and the same file that remembers your language can also record your browsing across thousands of sites. Cookies can be stolen if a connection is not encrypted, which is why secure flags matter, and they are being phased out for cross-site tracking, with browsers and regulators pushing replacements that reveal less about individuals.
Cookies checklist
- Read the cookie banner before accepting, and reject marketing cookies if you do not want tracking.
- Check your browser’s cookie settings, and consider blocking third-party cookies entirely.
- Clear cookies regularly, especially for sites you no longer use.
- Use your browser’s private mode when you do not want cookies kept after the session.
- Keep your browser updated, so cookie protections and security flags work as intended.
- Be wary of sites that refuse to work unless you accept all cookies; that is not how consent is meant to work.
- Remember that clearing cookies logs you out of sites, so save passwords in a manager first.
- On a shared computer, clear cookies and log out when you finish, so the next person is not you.
- Check a site’s privacy policy if you want to know which cookies it sets and why.
Frequently asked questions
Are cookies dangerous?
Not on their own. A cookie is a small text file, not a program, so it cannot run code or install anything. The risk comes from what it is used for: tracking your browsing, or, if it is stolen, letting someone else pretend to be you on a site where you are logged in.
Should I accept all cookies?
There is no need to. Necessary cookies are fine and often exempt from consent, but marketing and analytics cookies are optional. Rejecting them usually changes nothing about how the site works, though some sites make the choice harder to find than it should be.
What happens if I delete all my cookies?
You will be logged out of every site, baskets will empty, and preferences such as language and region will reset. The sites themselves still work, and new cookies will be set as you browse. It is a useful spring clean, but expect to log in again everywhere.
What is the difference between first-party and third-party cookies?
First-party cookies are set by the domain in your address bar, and they usually make the site work. Third-party cookies are set by other domains whose content is embedded in the page, such as adverts, and they are the ones used to track you across different sites.
Do cookies work on phones?
Yes, mobile browsers use cookies in the same way as desktop browsers, and apps have their own equivalents, such as advertising identifiers. Clearing cookies in a phone browser works the same way, though in-app browsing may keep its own separate storage.
Are cookies being replaced?
For cross-site tracking, yes. Browsers are phasing out third-party cookies, and the advertising industry is moving to systems that group people by interest without identifying individuals. First-party cookies, which make sites work, are not going anywhere.
The bottom line
Cookies explained in one line is this: small files that give the web a memory, letting sites recognise you, remember your choices, and, in the case of third-party cookies, follow you across the web.
The practical lesson is to treat them as a choice, not a given: accept the ones that make sites work, decide the rest for yourself, and clear them now and then. A browser that blocks third-party cookies by default does most of the work for you, and the sites you use will keep working.
This article is general information about how cookies work, not legal advice about privacy or consent for a particular website.







