Definition
A cookie is a very small text file that a server saves in your web browser (Chrome, Safari, and so on) when you visit a website. The next time you come back to the same site, your browser shows the file and says, "Hey, I'm the person who was here last time."
The Punch Card at Your Favorite Coffee Shop
When you hand over the loyalty punch card from your wallet at your regular coffee shop, the barista knows who you are right away and stamps it. The barista doesn't have to memorize thousands of faces. The name and the number of stamps on the card are enough to show you're a regular.
Websites work the same way. By design, the basic rules of internet communication (the HTTP protocol) have no memory of whether a visitor was just there a moment ago. Every time you open a new page, you're treated like a total stranger.
So when you visit for the first time, the web server slips a small note (a cookie) into your browser's pocket. It holds data such as an ID number that shows you're a logged-in user, or the number of the item you just put in your cart. Each time you move to the next page, your browser quietly shows this note to the server, and the conversation continues without a break.
From Staying Logged In to Targeted Ads
Thanks to cookies, the items in your cart are still there when you move to another page of an online store. You can close the site and open it again the next day without typing your ID and password, and you'll still be logged in. That's cookies at work too.
But cookies don't only bring convenience. You've probably browsed shoes at an online store, then found ads for those very shoes following you around on news articles and social media.
That happens because a "third-party cookie" planted by an ad company records which sites you move through. It gathers the notes your browser left across many sites, figures out your interests, and shows you ads that fit.
To Be a Bit More Precise: Cookies vs. Cache
Many people mix up cookies and the cache, which both show up when you clear your browsing data. But they are kept on your computer for completely different purposes, and they hold completely different things.
The cache is a technique that downloads heavy chunks of files, such as a site's logo images and design styles, to your computer ahead of time so pages load faster. A cookie, on the other hand, is just a very light scrap of text, well under a few kilobytes (KB).
To be a bit more precise, a sensitive password itself is not written directly into a cookie. Instead, only a randomly generated ID (a session ID) goes into the cookie, and your real account information stays in a safe store inside the web server. That's how your personal information is protected.
Common misconceptions
Deleting cookies frees up a lot of storage space on your computer.
A cookie is a tiny file, just a few lines of text and a few kilobytes (KB) at most, so deleting it barely frees up any space. The cache, which temporarily stores images and videos, is what takes up a lot of room.
Cookies are malicious programs that break your computer.
A cookie is just a plain text note that can't run on its own. It can't damage programs or harm your system.
Where you meet it
Staying logged in at an online store so you don't have to re-enter your password for several days
Checking "Don't show this window again today" when you open a website
In one sentence
A cookie is a small text note a website leaves in your browser so it can remember your login status and settings.