A hash function is simply a function that takes in input value, and from that input creates an output value deterministic of the input value. For any x input value, you will always receive the same y output value whenever the hash function is run. In this way, every input has a determined output.

For those not quite familiar with what a function is, here’s the gist:

In this case, x is the input, and y is the result. This is the mathematical definition of a function, but let’s take a look at a real world hash function.

This is the hash function md5, which from any input data creates a 32 character hexadecimal output. Most hash functions are generally non-reversible (see why here), which means you can’t figure out the input if you only know the output – unless you try every possible input (which is called a brute-force attack). Hash functions also usually have an infinite input size – you could hash a single number or an entire book of text, and it would still produce the same size hash result.

Hash functions are often used for proving that something is the same as something else, without revealing the information beforehand. Here’s an example.

Let’s say Alice is bragging to Bob that she knows the answer to the challenge question in their Math class. Bob wants her to prove that she knows the answer, without her telling him what it is. So, Alice hashes her answer (let’s say the answer was 42) to produce this hash:

Alice gives this hash to Bob. Bob can not find out what the answer is from this hash – but when he finds the answer himself, he can hash his answer and if he gets the same result, then he knows that Alice did indeed have the answer. Hashes are often used in this context of verifying information without revealing it to the party that is verifying.