# Hash algorithm with the least chance for collision

Out of these algorithms…

• MD5
• SHA1
• SHA224
• SHA256
• SHA384
• SHA512

… which has the least chance of collision, and which is the most secure at the time of writing this?

• you literally ordered them from least secure to most secure – Richie Frame May 18 '16 at 18:24

As Richie Frame noted in the comments, you basically listed them in order of ascending collision resistance.

The latter hashes have greater collision resistance due to their increased output size. With the exception of SHA-1 and MD5, this is denoted by the number in the name of the algorithm. For example, SHA-512 produces 512 bits of output.

The size of the output influences the collision resistance due to the birthday paradox.

To quote Wikipedia:

The "birthday paradox" places an upper bound on collision resistance: if a hash function produces N bits of output, an attacker who computes only $2^{N/2}$ (or $\sqrt{2^N}$) hash operations on random input is likely to find two matching outputs.

So SHA-512 should have the greatest theoretical collision resistance.

Note that MD5 and SHA1 should probably not be selected as a candidate when developing anything new and should only be used for compatibility purposes when required.

The SHA-2 algorithms calculate their digests in an almost identical manner, so generally we assume they are equally secure, digest sizes aside.

• At this point, I think SHA1 also belongs in the "only for compatibility" category. – Gordon Davisson May 19 '16 at 0:58
• I disagree with the comment about not using MD5 and SHA1. It depends on your intended use for the hash. If you need it for some security-related purposes, then don't use them. If you need them for one of the many other uses for a hash, then they can work better than the more complex, slower functions. Let's say for example finding duplicate records by first hashing all entries in a table, finding duplicate hashes, then comparing the underlying records with matching hashes to see if they are really duplicates or not. The MD5 hash will work great for this purpose and be much faster. – Itsme2003 May 19 '16 at 4:18
• @Itsme2003 I understand and agree with you. However the OP did specifically inquire about the security of the algorithms in question and not their performance. And this is crypto.stackexchange: Generally when people talk about hash functions here, it's implied they are talking about a cryptographically secure one. – Ella Rose May 19 '16 at 4:28
• Comments about hash algorithms are correct in that it depends on what one is using them for. For say BloomFilters, faster is generally better since collisions come with the nature of the bit set implementation. – Darrell Teague May 30 at 0:37