Why is a SHA-1 Hash 40 characters long if it is only 160 bit?

AGrunewald picture AGrunewald · Sep 13, 2010 · Viewed 56.9k times · Source

The title of the question says it all. I have been researching SHA-1 and most places I see it being 40 Hex Characters long which to me is 640bit. Could it not be represented just as well with only 10 hex characters 160bit = 20byte. And one hex character can represent 2 byte right? Why is it twice as long as it needs to be? What am I missing in my understanding.

And couldn't an SHA-1 be even just 5 or less characters if using Base32 or Base36 ?

Answer

kennytm picture kennytm · Sep 13, 2010

One hex character can only represent 16 different values, i.e. 4 bits. (16 = 24)

40 × 4 = 160.


And no, you need much more than 5 characters in base-36.

There are totally 2160 different SHA-1 hashes.

2160 = 1640, so this is another reason why we need 40 hex digits.

But 2160 = 36160 log362 = 3630.9482..., so you still need 31 characters using base-36.