Hash functions explained in a simple way
Understanding how hash functions work
4 min readAug 13, 2020
First, what is a hash function?
Simply speaking, a hash function is a mathematical function that takes any input size and convert it to a fixed output size. Consider this simple hash function H(X) = Last digit of (X)
- H(1234) = 4.
- H(12567) = 7.
- H(127) = 7.
- H(1111111111) = 1.
- H(24)=4.
- H(24)=4.
So no matter what is the input and its size, we’re returning a one digit output. Another important property is that the same input will always give you the same output. H(24) will always be 4.
In summary:
- A hash function generates a fixed size output (called digest or hash)
- For any input size or length, we get always the same fixed output size
- Totally deterministic: for the same input we get always the same output
- It’s not a complicated operation to get the hash of any input (very easy)
- Several inputs can have the same hash (like here 127 and 12567 both have 7 as hash). That’s called a hash collision. It’s natural since the output has a fixed size, and…