<blockquote>
  <p>Why raw Bitcoin transaction are in hex format?</p>
</blockquote>

<p>They are not. </p>

<p>So far as I know and have read.</p>

<h1>Bitcoin raw format</h1>

<p>According to <a href="https://bitcoin.org/en/developer-reference" rel="noreferrer">https://bitcoin.org/en/developer-reference</a></p>

<blockquote>
  <p>Bitcoin transactions are broadcast between peers in a <strong>serialized byte format, called raw format</strong>. It is this form of a transaction which is SHA256(SHA256()) hashed to create the TXID and, ultimately, the merkle root of a block containing the transaction—making the transaction format part of the consensus rules.</p>
</blockquote>

<p>and <a href="https://bitcoin.org/en/glossary/serialized-transaction" rel="noreferrer">https://bitcoin.org/en/glossary/serialized-transaction</a> defines <strong>Serialized Transaction, Raw Transaction</strong> as</p>

<blockquote>
  <p>Complete transactions in their <strong>binary format</strong>; often represented using hexadecimal. Sometimes called raw format because of the various Bitcoin Core commands with “raw” in their names</p>
</blockquote>

<p>(my emphasis)</p>

<p>So the form transmitted over the wire is not composed of ASCII characters 0-9A-F (hexadecimal) but of numbers and other values in a normal binary form.</p>

<hr>

<h1>Hexadecimal</h1>

<p>Software engineers like to use a hexadecimal encoding when writing and reading documentation. This hexadecimal encoding is simply one of many equally-valid visual-representations (binary, octal, ...). It just happens to be convenient and familiar to software engineers.</p>

<p>To take a specific example, the first part of a transaction is a version number. This could have the value 2. It is of data type int32_t, so it is 32 binary bits in length and represents a signed integer. I can write the value as 2 (decimal) or as 00000000000000000000000000000010 (binary) or as 00000002 (hex) but these are all just visual representations, none of them have any special meaning, you can't say that the value 2 is not transmitted. You could inspect and interpret that data using a tool that shows octal or binary or decimal or base 17 or any other arbitrary representation.</p>

CC BY-SA 4.0
2020-05-09T20:47:00.207Z
2020-05-09T21:00:50.277Z
2020-05-09T21:00:50.277Z
RedGrittyBrick
<p>Because unlike addresses, hex raw transactions aren't meant to be seen or used by end-users. Hex is easy to encode and decode (every two character in hex represents one byte*, whereas in base64 one character is 3/4 byte and Base58 is log(58)/log(256) = 0.7322476244 bytes) so it is convenient if you want to debug your implementation.</p>

<p>*: which means if you can find an erroneous byte in the transaction that you can CTRL+F for that byte in the serialized hex transaction and change it since unlike Base58 or Base64 an encoded character depends on the part of only one byte and never two neighboring bytes. Hex is the highest base with that property. Binary (1 bit divides 8 bits), Quaternary (2 bits divide 8 bits), not octal (3 bits don't divide 8 bits), and hexadecimal (4 bits is the largest divisor of 8 that isn't 8) are other bases with that property, so hex is the most efficient one among them.</p>

<p>Or simply, it was created as an <em>internal</em> tool which didn't need the complexity of a new format that provides space efficiency or avoiding similar characters (or checksum, even though hex doesn't depend on checksum) that is user-friendly.</p>

<p>From Bitcoin QT <a href="https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.7.0.md" rel="nofollow noreferrer">0.7.0 release notes</a>:</p>

<blockquote>
  <p>Added raw transaction API. See <a href="https://gist.github.com/2839617" rel="nofollow noreferrer">https://gist.github.com/2839617</a></p>
</blockquote>

<p>Gavin Andresen, who <a href="https://github.com/bitcoin/bitcoin/pull/1456" rel="nofollow noreferrer">created and submitted</a> the hex transaction encoding code to Bitcoin Core/QT <a href="https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2012-June/001528.html" rel="nofollow noreferrer">wrote</a>:</p>

<blockquote>
  <p>I considered parsing/writing BIP 10 format for raw transactions, but
  decided that reading/writing BIP 10 format should happen at a higher
  level and not in the low-level RPC calls. So 'raw transactions' are
  simply hex-encoded into JSON strings, and encoding/decoding them is
  just a couple of lines of already-written-and-debugged code.</p>
</blockquote>

CC BY-SA 4.0
2020-05-09T09:00:50.060Z
2020-05-09T16:01:56.013Z
2020-05-09T16:01:56.013Z
MCCCS
<p>Why are Bitcoin raw transactions in hexadecimal format? I am looking for scientific articles / books on this topic and I can't find anything, so my question is: why are they in hexadecimal and can there be any article on this topic?</p>

CC BY-SA 4.0
2020-05-20T08:47:39.197Z
Related: https://bitcoin.stackexchange.com/q/94991
MCCCS
<bitcoin-core><transactions><blockchain><protocol><raw-transaction>
Why raw Bitcoin transaction are in hex format?
M A
# Why raw Bitcoin transaction are in hex format?

(Asked by: username_0 on 2020-05-09)

Why are Bitcoin raw transactions in hexadecimal format? I am looking for scientific articles / books on this topic and I can't find anything, so my question is: why are they in hexadecimal and can there be any article on this topic?

**Tags:** bitcoin-core, transactions, blockchain, protocol, raw-transaction

> **Comments:**
> **username_1**: Related: https://bitcoin.stackexchange.com/q/94991  

---

## 2 answers

### Answer by username_1 on 2020-05-09. Score: 6 | Accepted answer

Because unlike addresses, hex raw transactions aren't meant to be seen or used by end-users. Hex is easy to encode and decode (every two character in hex represents one byte\*, whereas in base64 one character is 3/4 byte and Base58 is log(58)/log(256) = 0.7322476244 bytes) so it is convenient if you want to debug your implementation.

\*: which means if you can find an erroneous byte in the transaction that you can CTRL+F for that byte in the serialized hex transaction and change it since unlike Base58 or Base64 an encoded character depends on the part of only one byte and never two neighboring bytes. Hex is the highest base with that property. Binary (1 bit divides 8 bits), Quaternary (2 bits divide 8 bits), not octal (3 bits don't divide 8 bits), and hexadecimal (4 bits is the largest divisor of 8 that isn't 8) are other bases with that property, so hex is the most efficient one among them.

Or simply, it was created as an *internal* tool which didn't need the complexity of a new format that provides space efficiency or avoiding similar characters (or checksum, even though hex doesn't depend on checksum) that is user-friendly.

From Bitcoin QT [0.7.0 release notes](https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.7.0.md):

> Added raw transaction API. See <https://gist.github.com/2839617>

Gavin Andresen, who [created and submitted](https://github.com/bitcoin/bitcoin/pull/1456) the hex transaction encoding code to Bitcoin Core/QT [wrote](https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2012-June/001528.html):

> I considered parsing/writing BIP 10 format for raw transactions, but
> decided that reading/writing BIP 10 format should happen at a higher
> level and not in the low-level RPC calls. So 'raw transactions' are
> simply hex-encoded into JSON strings, and encoding/decoding them is
> just a couple of lines of already-written-and-debugged code.


---

### Answer by username_2 on 2020-05-09. Score: 5

> Why raw Bitcoin transaction are in hex format?

They are not.

So far as I know and have read.

# Bitcoin raw format

According to <https://bitcoin.org/en/developer-reference>

> Bitcoin transactions are broadcast between peers in a **serialized byte format, called raw format**. It is this form of a transaction which is SHA256(SHA256()) hashed to create the TXID and, ultimately, the merkle root of a block containing the transaction—making the transaction format part of the consensus rules.

and <https://bitcoin.org/en/glossary/serialized-transaction> defines **Serialized Transaction, Raw Transaction** as

> Complete transactions in their **binary format**; often represented using hexadecimal. Sometimes called raw format because of the various Bitcoin Core commands with “raw” in their names

(my emphasis)

So the form transmitted over the wire is not composed of ASCII characters 0-9A-F (hexadecimal) but of numbers and other values in a normal binary form.

---

# Hexadecimal

Software engineers like to use a hexadecimal encoding when writing and reading documentation. This hexadecimal encoding is simply one of many equally-valid visual-representations (binary, octal, ...). It just happens to be convenient and familiar to software engineers.

To take a specific example, the first part of a transaction is a version number. This could have the value 2. It is of data type int32\_t, so it is 32 binary bits in length and represents a signed integer. I can write the value as 2 (decimal) or as 00000000000000000000000000000010 (binary) or as 00000002 (hex) but these are all just visual representations, none of them have any special meaning, you can't say that the value 2 is not transmitted. You could inspect and interpret that data using a tool that shows octal or binary or decimal or base 17 or any other arbitrary representation.


---

