Workshop Diary is an ongoing series about how tools actually get built, in my own projects and my clients’.
I wanted to know how many people visit my site, but I didn’t want to collect personal data about my visitors. At first hearing that’s a contradiction. To count visitors you have to tell them apart, and telling them apart usually means storing something identifying. So how do you count people without storing them? The answer is one of the most elegant tricks in computing: hashing. This is a theoretical piece on how you can know how many without knowing who.
Why an IP address is personal data
Let’s start with why there’s a problem at all. When your browser fetches a page, it leaves behind an IP address, the string of numbers that says where the traffic came from. It’s not a name, but it’s still an identifier: it singles out a connection and often, in practice, a household or a person. That’s exactly why data protection law treats an IP address as personal data. And storing personal data brings a whole truckload of obligations: consents, retention periods, records of processing, and above all the responsibility that the data doesn’t leak. That’s a lot of ballast just to count visitors. I didn’t want to carry that ballast. I just wanted to know whether ten people or a hundred visit my site.
What hashing is, simply
This is where the hash function enters. It’s a mathematical machine that works in one direction: you feed in any data, and out comes a fixed-length ”fingerprint”, a seemingly random string. Two things are essential. First, the same input always produces the same fingerprint. Second, you can’t compute the original input back from the fingerprint, the function only goes forward, not back.
Think of it like a real fingerprint. You can compare two fingerprints and conclude ”these are from the same finger”, but from the fingerprint itself you don’t read the person’s name. Hashing does the same for data: it gives you a way to say ”this is the same as that” without revealing what it is. That property is the heart of the whole thing.
How it helps with counting
Now the puzzle clicks together. Instead of storing the IP address 84.23.something.something, I store the hash computed from it, the fingerprint. When another visit comes from the same address, it produces the same hash, and I can conclude it’s the same visitor. I get to count how many different visitors came. But that stored fingerprint doesn’t tell me who the visitor is or where they came from. I get the number without the identity. That’s exactly what I wanted: I know forty different people came, without knowing a single thing about any of them.
But here’s the trap, and this is the important part
If I stopped here, I’d be giving you a dangerous half-truth. Hashing alone isn’t enough, and it’s honest to say so plainly. The problem is this: there’s a limited number of IP addresses. There are only about four billion IPv4 addresses, to a computer that’s a small number. An attacker can compute the hash of every possible IP address once, make an index of them, and then look up your ”anonymous” hash to see directly which address produced it. The fingerprint turns back into a name. So naive hashing is a false sense of security, and it’s worse than no protection at all, because you think you’re safe when you’re not.
Fortunately the trap can be avoided, and here come the real tools. The first is a salt: before hashing, a secret extra is added to the input that the attacker doesn’t know. Then precomputed indexes are useless, because they were computed without that salt. The second is rotating the salt at regular intervals, for example daily: when yesterday’s salt is thrown away, yesterday’s and today’s hashes can no longer be linked to the same visitor. That limits tracking to a single day and prevents long-term tracing. The third is truncation: only part of the hash is kept, making it deliberately lossy. You get some collisions, meaning two different visitors can look the same, but since I only wanted an approximate number anyway, that’s an acceptable price for privacy.
It’s risk reduction, not magic
I want to be honest here, because exaggeration in security is dangerous. Even a well-salted, daily-rotating, truncated hash is not perfect anonymisation. Combined with enough other information, it too could in theory be traced back to a person. The point isn’t perfection but proportion: I keep far less, for far shorter, than if I stored the raw IP address as such. That’s privacy by design, collect the least that still answers your question. My question was ”how many”, not ”who”, so I store nothing that would answer ”who”.
Why this is worth knowing even if you never touch a website
Even if you never count visitors, here’s a principle that applies widely. Whenever you need to recognise ”the same” without storing ”what”, counting uniques, removing duplicates, tracking volumes. It’s worth asking: could I keep a fingerprint instead of the thing itself? The less sensitive data you hold, the less you have to lose. The best data breach is the one where the stolen data is useless, because you never kept the sensitive version in the first place. Security isn’t only putting locks around the data you have. It’s also thinking about what data you don’t need to take into your hands at all.
Finally
Let’s return to that original contradiction. I wanted to count visitors without collecting personal data, and it turned out to be entirely possible, as long as you use the right tools and are honest about their limits. I can know that forty different people visited my site today without knowing a single one’s name, address or anything else. It’s not a compromise between analytics and privacy where you skimp on both. It’s getting both at once, as long as you build it right from the start. And that, to me, is the finest part of computing: that an elegant solution doesn’t choose between two goods, it gives you both.