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:
- Previous transaction hash (32 bytes): The transaction ID of the UTXO being spent, in reverse byte order (little-endian). If you see
a1b2c3..., the actual transaction ID on the blockchain is...c3b2a1. You can reverse each pair of hex characters to get the standard big-endian transaction ID. - Previous output index (4 bytes): Which output from that previous transaction is being spent. This is a little-endian 32-bit integer. Index 0 is the first output.
- ScriptSig length (VarInt): How many bytes the unlocking script takes.
- ScriptSig (variable length): The unlocking script, usually containing a signature and a public key. This is raw script bytes, not human-readable opcodes.
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:
- Value (8 bytes): The amount of bitcoin in satoshis, little-endian. To get bitcoin, divide by 100,000,000. For example,
00e1f50500000000reversed is0000000005f5e100, which equals 100,000,000 satoshis, or 1 bitcoin. - ScriptPubKey length (VarInt): How many bytes the locking script takes.
- ScriptPubKey (variable length): The locking script that specifies who can spend this output. This is where addresses appear, encoded as a script.
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:
- Version:
01000000→ version 1. - Input count:
01→ one input. - Previous tx hash:
a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0(32 bytes). Reverse each pair to get the real transaction ID. - Previous output index:
01000000→ index 1 (little-endian). - ScriptSig length:
6a→ 106 bytes. - ScriptSig: The next 106 bytes (the signature and public key).
- Output count:
01→ one output. - Value:
a086010000000000→ reversed is00000000000186a0→ 100,000 satoshis (0.001 BTC). - ScriptPubKey length:
19→ 25 bytes. - ScriptPubKey:
76a914...88ac→ a standard P2PKH address. - 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:
- Version (4 bytes)
- Marker (1 byte, always
00) - Flag (1 byte, always
01) - Input count (VarInt)
- Inputs (each with the same fields, but ScriptSig is usually empty or minimal)
- Output count (VarInt)
- Outputs (same as non-segwit)
- Witness data (for each input, a count of witness items, then each item's length and data)
- Locktime (4 bytes)
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.