Input

Outputs that are consumed in a transaction

Diagram showing an input as being the outputs being consumed in a bitcoin transaction.

An input is an output that is being spent in a transaction. It's basically a reference to a previously unspent output, along with some unlocking code that unlocks the output so that it can be spent.

You can have multiple inputs in a transaction. This is because you sometimes need to consume multiple outputs (as inputs) to be able to create the total amount you want to send in the transaction.

Most transactions tend to have 1 or 2 inputs, but you can have thousands of inputs if you want to. However, the more inputs you have, the bigger the transaction is going to be (in bytes), which will make it more expensive as transactions are selected for mining based on the size of the fee per the amount of space they take up in a block.

So when you make a bitcoin transaction, you want to strategically select the fewest inputs that will allow you to create the total amount you want to send.

Structure

What does a transaction input do?

Diagram of the structure of a transaction input.

The input section of raw transactions has the following structure:

Field Example Size Format Description
TXID [TXID] 32 bytes Natural Byte Order The TXID of the transaction containing the output you want to spend.
VOUT 01000000 4 bytes Little-Endian The index number of the output you want to spend.
ScriptSig Size 6b variable Compact Size The size in bytes of the upcoming ScriptSig.
ScriptSig [script] variable Script The unlocking code for the output you want to spend.
Sequence fdffffff 4 bytes Little-Endian Set whether the transaction can be replaced or when it can be mined.

This structure is repeated for every input being included in the transaction.

As you can see, each input references a previous output by its TXID and VOUT, and then provides the unlocking code to unlock that output for spending via the ScriptSig field.

Diagram showing how the fields of a transaction input select and unlock a previous output.

For Segwit locking scripts (e.g. P2WPKH, P2WSH) the unlocking code is moved from the ScriptSig to the Witness field.

Examples

What does a transaction input look like?

1. One Input

This is a very basic transaction with one input:

02000000019945a5a440f2d3712ff095cb1efefada1cc52e139defedb92a313daed49d5678010000006a473044022031b6a6b79c666d5568a9ac7c116cacf277e11521aebc6794e2b415ef8c87c899022001fe272499ea32e6e1f6e45eb656973fbb55252f7acc64e1e1ac70837d5b7d9f0121023dec241e4851d1ec1513a48800552bae7be155c6542629636bcaa672eee971dcffffffff01a70200000000000017a9148ce773d254dc5df886b95848880e0b40f10564328700000000
{
  "version": "02000000",
  "inputcount": "01",
  "inputs": [
    {
      "txid": "9945a5a440f2d3712ff095cb1efefada1cc52e139defedb92a313daed49d5678",
      "vout": "01000000",
      "scriptsigsize": "6a",
      "scriptsig": "473044022031b6a6b79c666d5568a9ac7c116cacf277e11521aebc6794e2b415ef8c87c899022001fe272499ea32e6e1f6e45eb656973fbb55252f7acc64e1e1ac70837d5b7d9f0121023dec241e4851d1ec1513a48800552bae7be155c6542629636bcaa672eee971dc",
      "sequence": "ffffffff"
    }
  ],
  "outputcount": "01",
  "outputs": [
    {
      "amount": "a702000000000000",
      "scriptpubkeysize": "17",
      "scriptpubkey": "a9148ce773d254dc5df886b95848880e0b40f105643287"
    }
  ],
  "locktime": "00000000"
}

Transaction: 05d350c8a65010bbe9d220b2accd7601b4c6541b7c6d7f5ad451efbcc07f8d66

This transaction references the output 1 from transaction 78569dd4ae3d312ab9edef9d132ec51cdafafe1ecb95f02f71d3f240a4a54599, which has a value of 3453 sats. It then "sends" some of this amount to another address by creating one new output with a value of 679 sats.

The remainder of 2774 sats went to the miner as the transaction fee.

Little-Endian. The amount field in raw transactions is in little-endian. So if you convert a702000000000000 to big-endian you get 00000000000002a7, and in decimal this is 679.

Input Amounts. The inputs in raw transaction data do not actually contain the value of the output being spent. To find its value you need to go back to the transaction that created the output.

2. Two Inputs

This transaction has two inputs:

0200000002e925fec58184fe99a4789993b62963b0813851793350b1aec99f3e75466225a5190000006a473044022046e23b8f6b749a15b0571848fe2b86bfbe7e158b23f37fb0335be0a71f48a5dd022076640b2d39659c26224c9e67101b34e1394a38ff08a4bdd88d7503f63e54adc5012103b3e19c8169b81d15ec21f9d0f3ed4b2f18c7c9e1149ce5f7ddebed7732724b9fffffffffca45253a9f908429e09986454e83dfaab6ea30502356078477c81f57967a59641f0000006b483045022100f39a8b1f91e5293448a05c642362e510a718d1fc04e781a3778a51a1abb968a8022031ce768c5ff01c4899f24f8600d67777b3672c9e44ed5b1377672cfe89ef354b012103b3e19c8169b81d15ec21f9d0f3ed4b2f18c7c9e1149ce5f7ddebed7732724b9fffffffff01674275000000000017a91484504805e56355c8cb8fc06032ce352920edfc068700000000
{
  "version": "02000000",
  "inputcount": "02",
  "inputs": [
    {
      "txid": "e925fec58184fe99a4789993b62963b0813851793350b1aec99f3e75466225a5",
      "vout": "19000000",
      "scriptsigsize": "6a",
      "scriptsig": "473044022046e23b8f6b749a15b0571848fe2b86bfbe7e158b23f37fb0335be0a71f48a5dd022076640b2d39659c26224c9e67101b34e1394a38ff08a4bdd88d7503f63e54adc5012103b3e19c8169b81d15ec21f9d0f3ed4b2f18c7c9e1149ce5f7ddebed7732724b9f",
      "sequence": "ffffffff"
    },
    {
      "txid": "ca45253a9f908429e09986454e83dfaab6ea30502356078477c81f57967a5964",
      "vout": "1f000000",
      "scriptsigsize": "6b",
      "scriptsig": "483045022100f39a8b1f91e5293448a05c642362e510a718d1fc04e781a3778a51a1abb968a8022031ce768c5ff01c4899f24f8600d67777b3672c9e44ed5b1377672cfe89ef354b012103b3e19c8169b81d15ec21f9d0f3ed4b2f18c7c9e1149ce5f7ddebed7732724b9f",
      "sequence": "ffffffff"
    }
  ],
  "outputcount": "01",
  "outputs": [
    {
      "amount": "6742750000000000",
      "scriptpubkeysize": "17",
      "scriptpubkey": "a91484504805e56355c8cb8fc06032ce352920edfc0687"
    }
  ],
  "locktime": "00000000"
}

Transaction: 42563ae3e391d74de7160e64ebfc730885306faad799197b80ebe5fb1386b7a2

This transaction references the following previous outputs for use as inputs:

  1. a5256246753e9fc9aeb1503379513881b06329b6939978a499fe8481c5fe25e9:25 (Value = 1000000 sats)
  2. 64597a96571fc877840756235030eab6aadf834e458699e02984909f3a2545ca:31 (Value = 6690000 sats)

It then creates a new output with a value of 7684711 sats. The remainder of 5289 sats went to the miner as the transaction fee.

So as you can see, you can collect multiple inputs together to create the total amount you want to send in the transaction, but it does make the transaction larger.

3. Pizza Transaction (131 Inputs)

This is the famous pizza transaction, which has 131 inputs:

a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d (click to view the raw transaction)

This transaction is collecting many smaller inputs together to create one large 10,000 BTC output.

These transactions tend to happen when you've received multiple small payments and want to make send a large amount in one go. This is perfectly normal, but it just means that your transaction is going to be quite large (in terms of bytes) so you'll be paying more in fees to get this transaction mined.

It's more cost-effective to have few high-value outputs in your wallet rather than many low-value outputs. When fees are low, it's sometimes a good idea to consolidate lots of small outputs in to one larger one to save on fees when you come to make a transaction later on when the fees may be higher.

The most inputs I've ever seen in one transaction is in 52539a56b1eb890504b775171923430f0355eb836a57134ba598170a2f8980c1, which contains 20,000 inputs in total.

Coinbase

A coinbase is a special type of input found in coinbase transactions.

The input for a coinbase transaction doesn't need to reference any previous outputs, as a coinbase transaction is simply used to collect the block reward. Therefore, the TXID is set to all zeros, the VOUT is set to the maximum value, and a miner is free to put any data they like inside the ScriptSig.

For example, this is the coinbase transaction for block 56,214:

01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff070453ec131c0108ffffffff0100f2052a01000000434104f5865dd3ec943e68f85e811ddb1f1cbad26933992e2d48941e1e040a71b3333ff51cb789348e6741bdf6d493e4394762f1b4542c97ae8640ed09d5a692b3c976ac00000000
{
  "version": "01000000",
  "inputcount": "01",
  "inputs": [
    {
      "txid": "0000000000000000000000000000000000000000000000000000000000000000",
      "vout": "ffffffff",
      "scriptsigsize": "07",
      "scriptsig": "0453ec131c0108",
      "sequence": "ffffffff"
    }
  ],
  "outputcount": "01",
  "outputs": [
    {
      "amount": "00f2052a01000000",
      "scriptpubkeysize": "43",
      "scriptpubkey": "4104f5865dd3ec943e68f85e811ddb1f1cbad26933992e2d48941e1e040a71b3333ff51cb789348e6741bdf6d493e4394762f1b4542c97ae8640ed09d5a692b3c976ac"
    }
  ],
  "locktime": "00000000"
}

Transaction: 7b9301882a8527588d697462c2e394fa3d522eb86de72cc12694420c4a91196b

This transaction has an input that does not actually reference any previous outputs for spending, but it is still able to create a new output of 50 BTC, which means that this transaction is used for the new issuance of bitcoins.

BIP 34: After block height 227,836 the start of the ScriptSig must contain the height of the current block.

Coin Selection

Can you choose your own transaction inputs?

If you're using a bitcoin wallet to make a transaction, a good wallet will allow you to select your own inputs for your transaction.

A good example of a wallet that allows you to do this is Electrum:

Screenshot of Electrum coin selection screen.
Using Electrum to select specific outputs for use as inputs in a new transaction.

So the wallet will show you the outputs that you have available to spend, and you can choose the ones you want to use as inputs in your next transaction. The benefit of this is you can choose which coins will be associated with the destination address, which can be beneficial for privacy.

However, many wallets aimed at beginners will not have this feature. Instead, they will automatically select the most efficient combination of inputs for you, and not burden you with the complexity of selecting them yourself. This is perfectly fine, but if you want more control of your coins, you'll want to use a wallet that offers a "coin selection" or "coin control" feature where you can choose your own inputs if you want to.

Resources