babybitcoin.space

How do you read a raw bitcoin transaction hex?

A raw Bitcoin transaction hex is the complete transaction data encoded in hexadecimal format - the actual bytes that get broadcast to the network and recorded on the blockchain. Reading it means decoding those bytes into the fields that describe who is spending how much, where the funds come from, and where they go. Every field has a fixed position, length, and interpretation, so you can work through the hex from left to right.

What you need before you start

You need the raw transaction hex itself. You can get one from a block explorer, from your own wallet's "raw transaction" export, or from a site that lists unconfirmed transactions. You also need to understand that Bitcoin uses little-endian byte order for most numeric fields - meaning the least significant byte comes first. If you see 01 02 and expect 0201, you have the byte order correct.

A hex editor or a simple online hex decoder will let you see each byte. A paper and pencil work too, but it is tedious.

The Structure of a Raw Transaction

A Bitcoin transaction has four main sections in order: version, input count, inputs, output count, outputs, and locktime. There is also a segwit section if the transaction uses segregated witness, but we will cover the non-segwit case first.

Version (4 bytes)

The first four bytes are the version number. In hex, this is typically 01000000 for version 1 transactions, or 02000000 for version 2. Because of little-endian encoding, 01 00 00 00 means version 1. Read these bytes as a 32-bit little-endian integer.

Input Count (1 byte, or more)

The next byte tells you how many inputs the transaction has. If the value is less than 0xFD (253), that single byte is the count. If it is 0xFD, the next two bytes are the count (little-endian). If 0xFE, the next four bytes. If 0xFF, the next eight bytes. This is called a "compact size unsigned integer" or "VarInt."

Each Input

Each input has four parts:

Output Count (VarInt)

Same format as input count. One byte for counts under 253, then extended as needed.

Each Output

Each output has three parts:

Locktime (4 bytes)

The last four bytes are the locktime. A value of 00000000 means the transaction can be mined immediately. A value less than 500,000,000 is a block height; a value greater than or equal to that is a Unix timestamp. Little-endian.

A Worked Example

Take this raw transaction hex (a simplified, real example):

0100000001a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0010000006a473044022100a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0022010a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f012103a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9fffffffff01a0860100000000001976a914a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b088ac00000000

Break it down:

  1. Version: 01000000 → version 1.
  2. Input count: 01 → one input.
  3. Previous tx hash: a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0 (32 bytes). Reverse each pair to get the real transaction ID.
  4. Previous output index: 01000000 → index 1 (little-endian).
  5. ScriptSig length: 6a → 106 bytes.
  6. ScriptSig: The next 106 bytes (the signature and public key).
  7. Output count: 01 → one output.
  8. Value: a086010000000000 → reversed is 00000000000186a0 → 100,000 satoshis (0.001 BTC).
  9. ScriptPubKey length: 19 → 25 bytes.
  10. ScriptPubKey: 76a914...88ac → a standard P2PKH address.
  11. Locktime: 00000000 → no lock.

Segwit Transactions

Segwit transactions (version 1 or later) add a marker and flag after the version, then a witness section after the outputs. The structure becomes:

The witness data does not affect the transaction ID, which is why segwit fixed transaction malleability.

Tools that do this for you

You do not have to decode hex by hand. Block explorers show decoded transactions in human-readable form. Bitcoin Core's decoderawtransaction RPC command takes a hex string and returns JSON with all fields labelled. Many online hex-to-transaction tools exist - but be careful: paste your transaction hex only into sites you trust, because a raw transaction hex can reveal your public keys.

What you learn by reading hex

Reading raw hex teaches you that a Bitcoin transaction is just data. There are no hidden fields, no encryption, no magic. Every byte has a purpose, and the format is designed to be parsed in one pass from left to right. Once you see the pattern, you can spot a coinbase transaction (no inputs), a transaction with many inputs and outputs, or a transaction with unusual locktime values. It is the most literal way to understand what a transaction actually is.

Not financial advice. babybitcoin.space publishes market data and general information about babybitcoin. Crypto assets are volatile and you can lose everything you put in. Nothing here is a recommendation to buy, sell or hold, and we make no price predictions.

Prices are sourced from third parties and may be delayed or wrong. Verify anything you intend to act on against a primary source.

Back to bitcoin