<p>SHA256 hashes are encoded in plain binary in bitcoin protocol and in block storage (32-bytes in little-endian byte order when treated as integers, which makes them effectively "base256"). The textual hex encoding is merely used for displaying and inputting hashes into the software. Hex is a widely used and understood format for representing arrays of bytes. Also, most cryptographic APIs already support parsing of hex strings into big integers and such, but base58 is not really widely used outside of Bitcoin.</p>

<p>There seems like little reason to change the way I/O of hashes is done as it would only add to confusion as to what a string is for. The purpose of Base58Check strings was not merely to shorten them (as Base64 could've been used for this), but also to eliminate some characters which look alike or are incompatible with the URI format because bitcoin addresses are intended for sharing.</p>

CC BY-SA 4.0
2020-03-29T09:51:02.383Z
Yeah i get why base58 is used rather than base64, but why was hex chosen to visulaise the hashes? Is it insecure to encode hashes with base58 on a protocol level? The reason i ask is that i am currently coding a cryptocurrency in rust. I am currently encoding the hashes in base58 and reuiring hashes have at least 4 A's before them as other difficulty algos (the ahsh must be < the diff) dont work as the hashes are never samll enough
Leah Cornelius
CC BY-SA 4.0
2020-03-29T17:13:29.690Z
See my answer: hex is much nicer to debug things.
Pieter Wuille
CC BY-SA 4.0
2020-03-28T20:36:43.090Z
2020-03-28T20:36:43.090Z
Mark H
<p>Mark H's answer is correct, but I think there is a more fundamental point: addresses are directly intended for human consumption. Transaction hashes (as well as public keys, block hashes, raw scripts, raw transactions, ...) are not. They are sometimes visualized, but this is primarily for debugging purposes. And hexadecimal is a very natural choice for debugging, as it's easy to see which bytes correspond to which characters.</p>

CC BY-SA 4.0
2020-03-28T21:05:26.183Z
2020-03-28T21:05:26.183Z
Pieter Wuille
<p>BTC sha256 hashes are hex encoded (as sha256 spits out bytes not a string), why is this? Surely using base58 would be more efficient as would use less space (would output a shorter string) </p>

<hash><base58>
Why are hashes base16 (hex) encoded rather than base58 encoded?
Leah Cornelius
# Why are hashes base16 (hex) encoded rather than base58 encoded?

(Asked by: username_0 on 2020-03-28)

BTC sha256 hashes are hex encoded (as sha256 spits out bytes not a string), why is this? Surely using base58 would be more efficient as would use less space (would output a shorter string)

**Tags:** hash, base58


---

## 2 answers

### Answer by username_1 on 2020-03-28. Score: 3 | Accepted answer

SHA256 hashes are encoded in plain binary in bitcoin protocol and in block storage (32-bytes in little-endian byte order when treated as integers, which makes them effectively "base256"). The textual hex encoding is merely used for displaying and inputting hashes into the software. Hex is a widely used and understood format for representing arrays of bytes. Also, most cryptographic APIs already support parsing of hex strings into big integers and such, but base58 is not really widely used outside of Bitcoin.

There seems like little reason to change the way I/O of hashes is done as it would only add to confusion as to what a string is for. The purpose of Base58Check strings was not merely to shorten them (as Base64 could've been used for this), but also to eliminate some characters which look alike or are incompatible with the URI format because bitcoin addresses are intended for sharing.

> **Comments:**
> **username_0**: Yeah i get why base58 is used rather than base64, but why was hex chosen to visulaise the hashes? Is it insecure to encode hashes with base58 on a protocol level? The reason i ask is that i am currently coding a cryptocurrency in rust. I am currently encoding the hashes in base58 and reuiring hashes have at least 4 A's before them as other difficulty algos (the ahsh must be < the diff) dont work as the hashes are never samll enough  
> **username_2**: See my answer: hex is much nicer to debug things.  

---

### Answer by username_2 on 2020-03-28. Score: 6

username_1's answer is correct, but I think there is a more fundamental point: addresses are directly intended for human consumption. Transaction hashes (as well as public keys, block hashes, raw scripts, raw transactions, ...) are not. They are sometimes visualized, but this is primarily for debugging purposes. And hexadecimal is a very natural choice for debugging, as it's easy to see which bytes correspond to which characters.


---

