IP hashing
Overview
IP hashing is a technique that runs a user's IP address through a hash function such as SHA-256 and turns it into a fixed-length string from which the original IP address can't be read directly. The resulting hash value is always the same for the same IP address, so it can be used to judge "whether this is the same person," but it makes it hard to identify "who this is." How hard depends on how the salt is handled, which is explained below. It is used as a way to meet two conflicting needs at once: keeping people anonymous while detecting misuse.
Choosing a hash function and implementation pitfalls
IPv4 has about 4.3 billion possible addresses, and even with IPv6 the prefixes actually in use are limited. Because of this, simply hashing an address carries the risk that the original IP can be looked up in reverse with a rainbow table attack (a method that computes the hash values of every IP in advance).
To counter this, a salt (a secret fixed string) is added when hashing. A third party who doesn't know the salt can't build a rainbow table, so identifying the original IP from a hash value becomes practically difficult. The salt is kept in an environment variable on the server or in a secrets management service, and it is not included in the source code.
Use in anonymous question services
In anonymous question services, IP hashing has two typical uses. First, it serves as the identifier for rate limiting that detects repeated posts from the same IP. If you keep a counter keyed by the hash value, you can limit how often someone posts without holding on to raw IP addresses.
Second, it can be used to generate the identifier assigned to an anonymous sender. If a short ID generated from the hash value is attached to each post, the receiving side can link several posts from the same person and keep track of them. However, this kind of ID is only a rough guide, and the same person may end up with different IDs because of a VPN or IP changes on a mobile connection.
When to use hashing and when to store the raw IP encrypted
You can't take the original IP directly out of a salted IP hash, so the hash value alone can't answer a disclosure request based on legal procedures. For this reason, some services adopt a design that, alongside IP hashing, encrypts the raw IP address with a symmetric-key cipher such as AES-256 and stores it. In that case, normal operations refer only to the hash value, and the encrypted IP is decrypted only when a disclosure request comes in.
This two-part storage method aims to balance privacy protection with legal compliance. By clearly separating the uses, with the hash value for everyday misuse detection and the encrypted IP for legal matters, it can keep unnecessary access to personal information to a minimum.