# Is it possible that two different messages have same hash code? [duplicate]

As I know a very common hash code has 256 bits.

From a message, it outputs a hash code that's 256 bits. That hash code should be unique to that message. That message can be something like email.

But a message can be very long, far longer than 256 bits.

Theoretically there can be 2^256 different hash codes, and that's insanely large number.

But if a message contains 1000 letters, each letter being 8 bits, that's 8000 bits. Also 2^8000 different messages possible. Even if we just talk about 2^1000 possible messages that's still huge. So we put a long string of bits, and produce a 256 bits named "hash code".

If we divide 2^1000 messages by 2^256 hash codes, there are 2^744 messages for each hash code.

How is it possible that a hash code is unique to a message? Shouldn't there be some collusions, like two different messages having same hash code?

• TL;DR: It's mathematically certain there are distinct messages with the same hash; yet by design a good hash makes it practically impossible to exhibit any concrete example of such collision. There is one (not $2^{744}$) hash codes for each message, because a hash function is a function. With the question's hypothesis, there is at least one hash code with at least $2^{744}$ messages; and for a hash that behaves like a pseudo-random function, there is about $2^{744}$ messages with a given hash code.
– fgrieu
Commented Dec 8, 2022 at 17:22