<blockquote>
<p>what bytes exactly should be removed</p>
</blockquote>
<p>Those corresponding to the Segwit data fields:</p>
<ul>
<li>segwit flag and marker after the version number (bytes 4-5 with zero-based indexing).</li>
<li>segwit witness data between final output and lock time</li>
</ul>
<p>In general you cannot say something like <em>remove bytes 100-166</em> because the length and number of inputs and outputs is not fixed - so start position varies and must be calculated by parsing the specific inputs and outputs. The number and length of witnesses also varies but the end of witness data (if present) will be 4 bytes before end of transaction data.</p>
<p>See <a href="https://bitcoin.stackexchange.com/q/113697/13866">What are the parts of a Bitcoin transaction in segwit format?</a></p>

CC BY-SA 4.0
2024-03-10T16:03:27.170Z
01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c0390d50700040679a85a04b568f50c0c901b845a1f79000000000000ffffffff029b7c0d4b0000000017a9145d603130872a1b981e2160cd74c52fc1ba8b96ae870000000000000000266a24aa21a9ed000a4c0ed9889ec350f77856bba12735669d5c4564b64703ff7aaee03c873af200000000
yep, double hash of this hex  results in correct txid
Meir
CC BY-SA 4.0
2024-03-10T14:33:58.557Z
2024-03-10T14:51:41.937Z
2024-03-10T14:51:41.937Z
RedGrittyBrick
<pre><code>txid = 4508d55cf0d93ac43cbbb13a3b63d7a1e146911745f049893fc6b2d84e4e1256
raw block data = 010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff1c0390d50700040679a85a04b568f50c0c901b845a1f79000000000000ffffffff029b7c0d4b0000000017a9145d603130872a1b981e2160cd74c52fc1ba8b96ae870000000000000000266a24aa21a9ed000a4c0ed9889ec350f77856bba12735669d5c4564b64703ff7aaee03c873af20120000000000000000000000000000000000000000000000000000000000000000000000000
</code></pre>
<p>(this is the coinbase transaction for block 000000000000000000299bafb05053bb4f043b7425848abdd57a6eadbe404393 )
but double_sha256(raw_block_data) != txid
I assume this is because in segwit  not all the raw data is hashed. what bytes exactly should be removed ? Why don't the blockchain explorers present the data that gives the txid ?
related:
<a href="https://bitcoin.stackexchange.com/questions/62044/how-to-compute-segwit-txid">How to compute SegWit txid?</a>
<a href="https://bitcoin.stackexchange.com/questions/89256/how-to-calculate-txid-for-segwit-transactions">How to calculate txid for segwit transactions?</a></p>

<segregated-witness><transaction-id>
Example of computing segwit txid from raw tx data
Meir
# Example of computing segwit txid from raw tx data

(Asked by: username_0 on 2024-03-10)

txid = 4508d55cf0d93ac43cbbb13a3b63d7a1e146911745f049893fc6b2d84e4e1256
raw block data = 010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff1c0390d50700040679a85a04b568f50c0c901b845a1f79000000000000ffffffff029b7c0d4b0000000017a9145d603130872a1b981e2160cd74c52fc1ba8b96ae870000000000000000266a24aa21a9ed000a4c0ed9889ec350f77856bba12735669d5c4564b64703ff7aaee03c873af20120000000000000000000000000000000000000000000000000000000000000000000000000

(this is the coinbase transaction for block 000000000000000000299bafb05053bb4f043b7425848abdd57a6eadbe404393 )
but double_sha256(raw_block_data) != txid
I assume this is because in segwit  not all the raw data is hashed. what bytes exactly should be removed ? Why don't the blockchain explorers present the data that gives the txid ?
related:
How to compute SegWit txid?
How to calculate txid for segwit transactions?

**Tags:** segregated-witness, transaction-id


---

## 1 answers

### Answer by username_1 on 2024-03-10. Score: 1 | Accepted answer

> what bytes exactly should be removed

Those corresponding to the Segwit data fields:

* segwit flag and marker after the version number (bytes 4-5 with zero-based indexing).
* segwit witness data between final output and lock time

In general you cannot say something like *remove bytes 100-166* because the length and number of inputs and outputs is not fixed - so start position varies and must be calculated by parsing the specific inputs and outputs. The number and length of witnesses also varies but the end of witness data (if present) will be 4 bytes before end of transaction data.

See [What are the parts of a Bitcoin transaction in segwit format?](https://bitcoin.stackexchange.com/q/113697/13866)

> **Comments:**
> **username_0**: 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1c0390d50700040679a85a04b568f50c0c901b845a1f79000000000000ffffffff029b7c0d4b0000000017a9145d603130872a1b981e2160cd74c52fc1ba8b96ae870000000000000000266a24aa21a9ed000a4c0ed9889ec350f77856bba12735669d5c4564b64703ff7aaee03c873af200000000 yep, double hash of this hex  results in correct txid  

---

