<p>When I look at the following Transaction Description <a href="https://en.bitcoin.it/wiki/Transaction" rel="nofollow noreferrer">Transactions</a> I see the following distinction so I conclude:</p>
<p>TxHeader:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">Field</th>
<th style="text-align: left;">Size (in bytes)</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">Version no</td>
<td style="text-align: left;">4</td>
</tr>
<tr>
<td style="text-align: left;">Flag</td>
<td style="text-align: left;">2 (optional only for segwit v0 right now)</td>
</tr>
<tr>
<td style="text-align: left;">In-counter</td>
<td style="text-align: left;">1 - 9 bytes (varint)</td>
</tr>
<tr>
<td style="text-align: left;">Out-counter</td>
<td style="text-align: left;">1 - 9 bytes (varint)</td>
</tr>
<tr>
<td style="text-align: left;">lock_time</td>
<td style="text-align: left;">4 bytes</td>
</tr>
</tbody>
</table>
</div>
<p>TxInput:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">Field</th>
<th style="text-align: left;">Size (in bytes)</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">list of inputs</td>
<td style="text-align: left;">(in-counter)-many inputs</td>
</tr>
</tbody>
</table>
</div>
<p>TxOutput:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th style="text-align: left;">Field</th>
<th style="text-align: left;">Size (in bytes)</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">list of inputs</td>
<td style="text-align: left;">(out-counter)-many inputs</td>
</tr>
</tbody>
</table>
</div>
CC BY-SA 4.0
2021-03-09T09:22:42.453Z
Can somebody confirm ?
norisgOG
CC BY-SA 4.0
2021-03-09T11:07:24.900Z
The header can vary. You are nearly right. Basically it starts with version and inputCount. If the inputCount = 0 then the inputCount is the flag and the inputCout follows. If the initial inputCount is > 0 then its the inputCount and the inputs are following.
Erhard Dinhobl
CC BY-SA 4.0
2021-03-09T11:07:56.767Z
FYFI I coded exactly that data reading: https://github.com/mrqc/bitcoin-blk-file-reader/blob/master/analyze.py
Erhard Dinhobl
CC BY-SA 4.0
2021-03-09T11:08:13.413Z
See the readTransaction(...) function there.
Erhard Dinhobl
CC BY-SA 4.0
2021-03-09T23:47:10.233Z
Ok so what your are essentially decribing is, how the algorithm is implemented,got it, but I think looking at your code when the 5 th byte is 0 then the next byte is the flag (not the already read inputCount) and the 7th Byte is the inputCount. Thanks for the Code Snippet very pratical for understanding
norisgOG
CC BY-SA 4.0
2021-03-10T07:38:16.623Z
Yes, but be aware: Inbetween those values the inputs' data is there, so you maybe dont want to include this data in a "header".
Erhard Dinhobl
CC BY-SA 4.0
2021-03-09T09:22:08.153Z
2021-03-09T09:22:08.153Z
norisgOG
<p>Related to post <a href="https://bitcoin.stackexchange.com/questions/84004/how-do-virtual-size-stripped-size-and-raw-size-compare-between-legacy-address-f">Murch Explanation of Segwit Tx Fee Rate</a> he breaks a TX down into:</p>
<ul>
<li>TxHeader</li>
<li>TxInput</li>
<li>TxOutput</li>
</ul>
<p>To calculate the weight and the final virtual size of a transaction (P2PKH,P2WPKH,P2SH-P2WPKH)</p>
<p>My question relates to what is the TxHeader in detail. I haven't heard about this classification in any articles.</p>

<transactions>
Bitcoin Transactions Detailed distinction between TxHeader TxInput TxOuput
norisgOG
# Bitcoin Transactions Detailed distinction between TxHeader TxInput TxOuput

(Asked by: username_0 on 2021-03-09)

Related to post [Murch Explanation of Segwit Tx Fee Rate](https://bitcoin.stackexchange.com/questions/84004/how-do-virtual-size-stripped-size-and-raw-size-compare-between-legacy-address-f) he breaks a TX down into:

* TxHeader
* TxInput
* TxOutput

To calculate the weight and the final virtual size of a transaction (P2PKH,P2WPKH,P2SH-P2WPKH)

My question relates to what is the TxHeader in detail. I haven't heard about this classification in any articles.

**Tags:** transactions


---

## 1 answers

### Answer by username_0 on 2021-03-09. Score: 1

When I look at the following Transaction Description [Transactions](https://en.bitcoin.it/wiki/Transaction) I see the following distinction so I conclude:

TxHeader:

| Field | Size (in bytes) |
| --- | --- |
| Version no | 4 |
| Flag | 2 (optional only for segwit v0 right now) |
| In-counter | 1 - 9 bytes (varint) |
| Out-counter | 1 - 9 bytes (varint) |
| lock\_time | 4 bytes |

TxInput:

| Field | Size (in bytes) |
| --- | --- |
| list of inputs | (in-counter)-many inputs |

TxOutput:

| Field | Size (in bytes) |
| --- | --- |
| list of inputs | (out-counter)-many inputs |

> **Comments:**
> **username_0**: Can somebody confirm ?  
> **username_1**: The header can vary. You are nearly right. Basically it starts with version and inputCount. If the inputCount = 0 then the inputCount is the flag and the inputCout follows. If the initial inputCount is > 0 then its the inputCount and the inputs are following.  
> **username_1**: FYFI I coded exactly that data reading: https://github.com/mrqc/bitcoin-blk-file-reader/blob/master/analyze.py  
> **username_1**: See the readTransaction(...) function there.  
> **username_0**: Ok so what your are essentially decribing is, how the algorithm is implemented,got it, but I think looking at your code when the 5 th byte is 0 then the next byte is the flag (not the already read inputCount) and the 7th Byte is the inputCount. Thanks for the Code Snippet very pratical for understanding  
> **username_1**: Yes, but be aware: Inbetween those values the inputs' data is there, so you maybe dont want to include this data in a "header".  

---

