What is Hash Collision?

Technology CommunityCategory: Hash TablesWhat is Hash Collision?
VietMX Staff asked 3 years ago

There’s always a chance that two different inputs for hash function will generate the same hash value. This is known as a hash collision. If a collision happens, you just compare the actual objects you are hashing to see if they match. What is the probability of a hash collision? This question is just a general form of the birthday problem from mathematics:

Given k randomly generated values, where each value is a non-negative integer less than N, what is the probability that at least two of them are equal?

Take the well-known hash function CRC32, for example. If you feed this function the two strings “plumless” and “buckeroo”, it generates the same value. This is known as a hash collision.

hash-collision

 

Assuming your hash values are 32-bit, 64-bit or 160-bit, the following table contains a range of small probabilities:

hash-collision