TeachMeBitcoin

Calculating the TXID

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

Calculating the TXID

The Transaction ID (TXID) is the primary key of the Bitcoin ecosystem. Just like a Block Hash, the TXID is a deterministic cryptographic result of the transaction data.

1. The Algorithm

A TXID is calculated by performing a Double-SHA256 hash on the serialized transaction data. $$TXID = SHA256(SHA256(Raw\ Transaction))$$

2. What is Hashed?

For a standard (non-SegWit) transaction, the hash includes:

If you change even a single bit in the signature (ScriptSig) or the recipient's address, the resulting TXID will be completely different.

3. Transaction Malleability

Because the signature is part of the data being hashed for the TXID, a problem called Transaction Malleability once existed.

4. Big-Endian vs. Little-Endian

Similar to block hashes, TXIDs are displayed in Big-Endian by block explorers but processed in Little-Endian by the protocol.

Step Action
1. Serialize Convert the TX fields into a raw byte stream.
2. Hash Apply SHA256 twice.
3. Finalize The resulting 32 bytes is the internal TXID.

In the next section, we will discuss how nodes use the TXID to reference spendability.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!