Output

Packages of bitcoins

Diagram showing the outputs in a bitcoin transaction.

An output is a package of bitcoins created in bitcoin transaction.

You can create multiple outputs in a transaction, where each output contains an amount of bitcoin and a lock on it. A future transaction can then spend these outputs (as inputs) by unlocking them, and create new outputs with new locks on them.

Diagram showing the outputs in from a previous transaction being used as the inputs in a new transaction (and creating more outputs).

So outputs are the building blocks for sending and spending money in bitcoin.

A transaction can only spend previously unspent outputs, and once an output has been spent it cannot be spent again.

Deposit Boxes

Diagram showing a transaction selecting outputs from the blockchain and adding new outputs in to it.

It's easiest to think of an output as a safe deposit box.

When you make a bitcoin transaction, you're selecting an existing deposit box, opening it up, and moving its contents in to new deposit boxes. The locks you place on these deposit boxes prevent anyone else from opening them up (other than the person you want to "send" the bitcoins to).

So you can think of the blockchain as one big vault of safe deposit boxes. Or as we call them in Bitcoin, outputs.

Change

Diagram showing a change output in a transaction.

When you spend an output in a transaction you have to use up the entire amount of the output; you can't just open up an output and only spend some of the bitcoins contained inside it, leaving the rest behind locked up in the original output.

So if the output contains more bitcoins than you'd like to actually send to someone, you need to create an extra change output to send the remaining bitcoins back to yourself.

Most transactions make use of a change output.

There's no specific output that you have to use for change. You could construct the transaction so that the first output contains your change (and the second output is the payment you're making), or even have multiple change outputs. There's no set rule, and you're free to create however many outputs in any order you like.

Nonetheless, the change input is typically the last output in a transaction.

Any leftover amount of bitcoins that do not get locked up in outputs will be classed as the transaction fee and will be collected by a miner. So if you forget to add a change output to your transaction, you will lose some bitcoins.

Structure

What does a transaction output do?

Diagram showing the basic structure of an output.

An output inside a raw transaction is just an amount (an integer) along with a locking script:

Field Example Size Format Description
Amount e99e060000000000 8 bytes Little-Endian The value of the output in satoshis.
ScriptPubKey Size 19 variable Compact Size The size in bytes of the upcoming ScriptPubKey.
ScriptPubKey [script] variable Script The locking code for this output.

This structure repeats for every output.

So on a technical level, outputs are pretty straightforward.

Amount

Diagram showing the amount field of a transaction output.

The amount field is 8 bytes in size, so it can hold the values between 0 (0x0000000000000000) and 18446744073709551615 (0xffffffffffffffff). The field is also in little-endian, so inside raw transaction data the bytes appear to be backwards.

The amount is also in satoshis (1 satoshi = 0.00000001 BTC).

Unit Converter
Little-Endian

That maximum value is equivalent to 184,467,440,737.09551615 BTC, which is more BTC than is in existence.

The amount field of an output can be zero if you want.

The total value of the outputs in a transaction cannot exceed the total value of the inputs.

ScriptPubKey Size

This field contains the size of the upcoming locking script.

It's also a compact size field, so whilst it's usually 1-byte, it can expand if it's indicating a very large upcoming locking script. These are the compact size fields of the most common locking scripts:

Type Compact Size Script Size
P2PK 23 or 43 35 or 67 bytes
P2PKH 19 25 bytes
P2SH 17 23 bytes
P2WPKH 16 22 bytes
P2WSH 22 34 bytes
Compact Size

ScriptPubKey

Diagram showing the scriptpubkey field of a transaction output.

The ScriptPubKey field contains the lock you want to place on the output.

There are various different types of locks you can place on an output, but the most common type is to lock the output to someone else's public key (i.e. address). These types of locks are referred to as P2PKH and P2WPKH.

Script

It's technically possible for the ScriptPubKey field to be empty. However, this would mean there would be no lock on the output, so anyone would be able to spend it.

Examples

What does a transaction output look like?

1 Output

01000000011fde77dd3bc6640714747f158e88260efe7f40236ee0446aca1a0808aec2caab010000006b483045022100f2c45824f970775daa1264f7b0779ee5df86359fab9ef47a0fee85ec97d46c0502201e1efe643c6c2bc56cced92a25c74158b01a5bfd06197a77851795a59fe5d80c0121034fb95ed3287f94561aa26df5ad19bb24762808ba278f7b26d1c85848f86a7ec4ffffffff0100e1f505000000001976a914299da5537e8b65bf45c70a9ece75988ebfca86b588ac00000000
{
  "version": "01000000",
  "inputcount": "01",
  "inputs": [
    {
      "txid": "1fde77dd3bc6640714747f158e88260efe7f40236ee0446aca1a0808aec2caab",
      "vout": "01000000",
      "scriptsigsize": "6b",
      "scriptsig": "483045022100f2c45824f970775daa1264f7b0779ee5df86359fab9ef47a0fee85ec97d46c0502201e1efe643c6c2bc56cced92a25c74158b01a5bfd06197a77851795a59fe5d80c0121034fb95ed3287f94561aa26df5ad19bb24762808ba278f7b26d1c85848f86a7ec4",
      "sequence": "ffffffff"
    }
  ],
  "outputcount": "01",
  "outputs": [
    {
      "amount": "00e1f50500000000",
      "scriptpubkeysize": "19",
      "scriptpubkey": "76a914299da5537e8b65bf45c70a9ece75988ebfca86b588ac"
    }
  ],
  "locktime": "00000000"
}

Transaction: 2c5ae87c8f15d1b7432358212dbe6ee51b8e24c6f071b0d708647611000510f7

This is a very basic transaction that only contains one output:

Output Amount (sats) Script Type
0 100000000 P2PKH

The amount field is 00e1f50500000000, and if we convert that from little-endian to big-endian we get 0000000005f5e100, and if we convert that from hexadecimal to decimal we get 100000000.

Little-Endian

This output also had a classic P2PKH locking script on it, which is always 25 bytes in size. We can identify this as a P2PKH script because they have a fixed pattern.

Script

Furthermore, if we check the previous transaction we can see that the only input had a value of 100050000 sats. So the leftover 50000 was counted as the transaction fee.

The inputs in a raw transaction do not tell you their value. So to work out the value of an input, you have to go back to the previous transaction that created the output and get the amount from there.

These one-output transactions are quite rare (outside of coinbase transactions), as they're basically moving all of the bitcoins from one address to another.

2 Outputs

01000000011cc6d0c72e9b8311c675ce9157c385ee939568965b9609d1ced52b7bdf356e15040000006b483045022100bcbe87cdc8aaf78e89c373a1528abd9fec9f45e78bc699e13b569a4c854b719d02206ffdeb0af05b61e7c81d4b8648339a3edbb6b23598233e7f6ab2aa5415816f2301210277f43598c17f8163d33167b79793722dda1115bbc68e03a0f354c8b162bd1d80ffffffff02e2b3190000000000160014af267b26ef0ebd333b80dac1546f7db5d048d0274814de0c000000001976a914ff1a978dd905cf676b2ee8870ba47728294e609588ac00000000
{
  "version": "01000000",
  "inputcount": "01",
  "inputs": [
    {
      "txid": "1cc6d0c72e9b8311c675ce9157c385ee939568965b9609d1ced52b7bdf356e15",
      "vout": "04000000",
      "scriptsigsize": "6b",
      "scriptsig": "483045022100bcbe87cdc8aaf78e89c373a1528abd9fec9f45e78bc699e13b569a4c854b719d02206ffdeb0af05b61e7c81d4b8648339a3edbb6b23598233e7f6ab2aa5415816f2301210277f43598c17f8163d33167b79793722dda1115bbc68e03a0f354c8b162bd1d80",
      "sequence": "ffffffff"
    }
  ],
  "outputcount": "02",
  "outputs": [
    {
      "amount": "e2b3190000000000",
      "scriptpubkeysize": "16",
      "scriptpubkey": "0014af267b26ef0ebd333b80dac1546f7db5d048d027"
    },
    {
      "amount": "4814de0c00000000",
      "scriptpubkeysize": "19",
      "scriptpubkey": "76a914ff1a978dd905cf676b2ee8870ba47728294e609588ac"
    }
  ],
  "locktime": "00000000"
}

Transaction: 4b5c918e95b98843a8340a6bb2dd61b4eee73ea632db85fb9a7eb538fd355588

This is a more typical transaction. It contains 2 outputs:

Output Amount (sats) Script Type
0 1684450 P2WPKH
1 215880776 P2PKH

So presumably the input (217582852 sats) was split in two: the first output being the payment to someone else, and the second output being the change being locked back to the original owner.

We can't be certain that the second output was the change however, as there's no designated way to set the change output on a transaction. But typically most wallets set the change output as the last output in a transaction.

3 Outputs

0100000002ec517e7b4c707c5e3afaf693aacbbd4ebe7d0d5c645381258c72e0e183b929d5000000008b483045022100afcc65e5ed4284de7229320007b3938d443721cf4c3a8be221e7d872c637e550022070e9fd53679633d5421024952960fa47403c91170a68aeb9193f19c8959b7f39014104f4c33b57af42019e38a756163d20f08da3d7e55b6810ed3c3d5355bff563573bf06c1900d65cea45583599e5ad966565695198239345fd04ea1a4ad3b13ad8d0ffffffff02d90d933c1d2f7a2283b9404de6a85c9aef9f4cbc96a212214c99c631a66e74010000008b483045022100c01185dc7196b0de04fba00a8e964e8ad98cd2a4516784c7f5312c887c45b27d0220700b2a9f8c4b845e7bfc703927a85c1ce0f52d10266996304ea1295ab0fca40f0141049a3d95bc9711a3fe30f98790d179caea0ef7ba5a683c3555a566687659e21b3c2c83a7db8267353cf2ddeb8f521d8c1d4f6dc8bc5fcc4e1534623a9d6c0675c5ffffffff03801a0600000000001976a914c0ea92934c59cf1bfa8db64deab8faac2b108ee588ac20a10700000000001976a914b58e94278b9dc5b3ca3d8337876bd747bb365e5388ac70900000000000001976a914b3c61b2cd26075419cb0302d1af241b8c7db62ed88ac00000000
{
  "version": "01000000",
  "inputcount": "02",
  "inputs": [
    {
      "txid": "ec517e7b4c707c5e3afaf693aacbbd4ebe7d0d5c645381258c72e0e183b929d5",
      "vout": "00000000",
      "scriptsigsize": "8b",
      "scriptsig": "483045022100afcc65e5ed4284de7229320007b3938d443721cf4c3a8be221e7d872c637e550022070e9fd53679633d5421024952960fa47403c91170a68aeb9193f19c8959b7f39014104f4c33b57af42019e38a756163d20f08da3d7e55b6810ed3c3d5355bff563573bf06c1900d65cea45583599e5ad966565695198239345fd04ea1a4ad3b13ad8d0",
      "sequence": "ffffffff"
    },
    {
      "txid": "02d90d933c1d2f7a2283b9404de6a85c9aef9f4cbc96a212214c99c631a66e74",
      "vout": "01000000",
      "scriptsigsize": "8b",
      "scriptsig": "483045022100c01185dc7196b0de04fba00a8e964e8ad98cd2a4516784c7f5312c887c45b27d0220700b2a9f8c4b845e7bfc703927a85c1ce0f52d10266996304ea1295ab0fca40f0141049a3d95bc9711a3fe30f98790d179caea0ef7ba5a683c3555a566687659e21b3c2c83a7db8267353cf2ddeb8f521d8c1d4f6dc8bc5fcc4e1534623a9d6c0675c5",
      "sequence": "ffffffff"
    }
  ],
  "outputcount": "03",
  "outputs": [
    {
      "amount": "801a060000000000",
      "scriptpubkeysize": "19",
      "scriptpubkey": "76a914c0ea92934c59cf1bfa8db64deab8faac2b108ee588ac"
    },
    {
      "amount": "20a1070000000000",
      "scriptpubkeysize": "19",
      "scriptpubkey": "76a914b58e94278b9dc5b3ca3d8337876bd747bb365e5388ac"
    },
    {
      "amount": "7090000000000000",
      "scriptpubkeysize": "19",
      "scriptpubkey": "76a914b3c61b2cd26075419cb0302d1af241b8c7db62ed88ac"
    }
  ],
  "locktime": "00000000"
}

Transaction: 79b8222bfac163571bbe31fcaecd69f703ff5f575fd778d6633005f3662e4aa7

This is a more complex transaction with 2 inputs and 3 outputs:

Output Amount (sats) Script Type
0 400000 P2PKH
1 500000 P2PKH
2 36976 P2PKH

This transaction could have been sending bitcoins to two different people at once, and then using the third output as change.

You can create as many outputs in a transaction as you like (as long as the transaction can fit inside a block), so you're not limited to only creating 1 or 2 outputs at a time. Therefore, you can send money to many different people in one transaction. Bitcoin transactions are very flexible.

The most outputs I've ever seen in a transaction is 13,107: dd9f6bbf80ab36b722ca95d93268667a3ea6938288e0d4cf0e7d2e28a7a91ab3

Zero Amount

0100000001e44e51e602eb117e8fa18e0e970ef530a399eaabefd69c5f89dbfdb0569a7cc701000000fd1b0100473044022057f6e6461cfdbaa55521b556e79ac23db4214ffda337d0bf5a41e791b1d2499c0220282ab1a6d485faf195d3f58d26a9c97bcf6c9fba1af454c45798321d1456081801483045022100ac33c53170c6db0984775810e77d0a31c35ce5592c5ab8b7c9489b11c90f221e02200ca5dcfe598ca1007cad4e41880c225f0de6061b337922304c05f10575a14616014c875241047bfd3c3a7abc765c34304d880435aeb7bf766ec2af7452d3b2667c71c9cb05303b124737ef401aed8b2977ac37f931b51e95601bad5047af9569338b4b064e92410455cf4a3ab68a011b18cb0a86aae2b8e9cad6c6355476de05247c57a9632d127084ac7630ad89893b43c486c5a9f7ec6158fb0feb708fa9255d5c4d44bc0858f852aeffffffff0290ecf032000000001976a914bcefb891e8ecd882fd9785e24258bad9b7b96e0788ac000000000000000017a914465a5922d985b0ab3f155e638ec5630ad5fffa448700000000
{
  "version": "01000000",
  "inputcount": "01",
  "inputs": [
    {
      "txid": "e44e51e602eb117e8fa18e0e970ef530a399eaabefd69c5f89dbfdb0569a7cc7",
      "vout": "01000000",
      "scriptsigsize": "fd1b01",
      "scriptsig": "00473044022057f6e6461cfdbaa55521b556e79ac23db4214ffda337d0bf5a41e791b1d2499c0220282ab1a6d485faf195d3f58d26a9c97bcf6c9fba1af454c45798321d1456081801483045022100ac33c53170c6db0984775810e77d0a31c35ce5592c5ab8b7c9489b11c90f221e02200ca5dcfe598ca1007cad4e41880c225f0de6061b337922304c05f10575a14616014c875241047bfd3c3a7abc765c34304d880435aeb7bf766ec2af7452d3b2667c71c9cb05303b124737ef401aed8b2977ac37f931b51e95601bad5047af9569338b4b064e92410455cf4a3ab68a011b18cb0a86aae2b8e9cad6c6355476de05247c57a9632d127084ac7630ad89893b43c486c5a9f7ec6158fb0feb708fa9255d5c4d44bc0858f852ae",
      "sequence": "ffffffff"
    }
  ],
  "outputcount": "02",
  "outputs": [
    {
      "amount": "90ecf03200000000",
      "scriptpubkeysize": "19",
      "scriptpubkey": "76a914bcefb891e8ecd882fd9785e24258bad9b7b96e0788ac"
    },
    {
      "amount": "0000000000000000",
      "scriptpubkeysize": "17",
      "scriptpubkey": "a914465a5922d985b0ab3f155e638ec5630ad5fffa4487"
    }
  ],
  "locktime": "00000000"
}

Transaction: 3ef405a8b0f3404e9c0c65e18776f19a3f213bd358566434d9313223be58d225

This is an example of a transaction with an output that contains an output with a value of 0 satoshis.

I'm not sure why this transaction created an empty output, but I'm just using this as an example to show that you can set the value of an output to zero if you want to.

Empty ScriptPubKey

0100000002a08d75950a62c4a7d3b2ce5d5d451f340d26e27ab88c8d1d6a4d1e875846035a00000000fd600100493046022100f078988f0448183b2439e6a210420a0cf6bd62b11fe6b1ec5bfe8366a28cfac4022100f6ef61d2888b74dd4d3eb065a853644f9dbd372e312d25f89eb339b7081ca4bc01493046022100c99192c8eb5fc7da5a73136e92ecb38e20541a3fbb31cd7a488c8182e899cef7022100a9427dbe6c878fffb0ece6cf7f89250e46f6f4582f809bc18fecfe273f5138a9014cc9524104a7a95441bb281f9f851556b8dcae7d5d85746e4382a852dcc8faa3a2320f442fed7d5b4f50d368cf4e18fb1642cfc4a5091e54d240aba9aeb74b07bcf95ad1d4410417b756f5562aa8b48d38fa25614391904dbfd7ef5a56e1d8b1e1c0b31200852a0ae3689350ed38be3d6de0c2472205f5ad697208784aa54174660cdf0b649b814104e35613163e133615ab272c30532c137f61344e14f36a146c3d4461863e5e5fcdc430206d08119771a18977d3a476f4889e5fb6c6eb5fbdd6ab7519e66b096fdb53aeffffffff4ba60a7b2dc4ba89f10bb7939a9b8a6d6735642e655ca173625594432a006acd01000000fd5e0100493046022100b7aa571bfb81fa57e0d366f41be7e1d451fbf9529cbb5b5f0df3e2b9edc59ad6022100c02138c790e4c84288a7f9338f217a035fb87c4c0716c2dcc3d4a950704f323001473044022041c21d0fa28adeab92a355b285f62fdc2b1bee4f16b0d78aac0d3be2c6e986b102202e73c88015ae7966aa3fd0e06d7f0bb1d2e231c502ee333cd1f5f3c5f6f3a320014cc9524104a7a95441bb281f9f851556b8dcae7d5d85746e4382a852dcc8faa3a2320f442fed7d5b4f50d368cf4e18fb1642cfc4a5091e54d240aba9aeb74b07bcf95ad1d4410417b756f5562aa8b48d38fa25614391904dbfd7ef5a56e1d8b1e1c0b31200852a0ae3689350ed38be3d6de0c2472205f5ad697208784aa54174660cdf0b649b814104e35613163e133615ab272c30532c137f61344e14f36a146c3d4461863e5e5fcdc430206d08119771a18977d3a476f4889e5fb6c6eb5fbdd6ab7519e66b096fdb53aeffffffff0100000000000000000000000000
{
  "version": "01000000",
  "inputcount": "02",
  "inputs": [
    {
      "txid": "a08d75950a62c4a7d3b2ce5d5d451f340d26e27ab88c8d1d6a4d1e875846035a",
      "vout": "00000000",
      "scriptsigsize": "fd6001",
      "scriptsig": "00493046022100f078988f0448183b2439e6a210420a0cf6bd62b11fe6b1ec5bfe8366a28cfac4022100f6ef61d2888b74dd4d3eb065a853644f9dbd372e312d25f89eb339b7081ca4bc01493046022100c99192c8eb5fc7da5a73136e92ecb38e20541a3fbb31cd7a488c8182e899cef7022100a9427dbe6c878fffb0ece6cf7f89250e46f6f4582f809bc18fecfe273f5138a9014cc9524104a7a95441bb281f9f851556b8dcae7d5d85746e4382a852dcc8faa3a2320f442fed7d5b4f50d368cf4e18fb1642cfc4a5091e54d240aba9aeb74b07bcf95ad1d4410417b756f5562aa8b48d38fa25614391904dbfd7ef5a56e1d8b1e1c0b31200852a0ae3689350ed38be3d6de0c2472205f5ad697208784aa54174660cdf0b649b814104e35613163e133615ab272c30532c137f61344e14f36a146c3d4461863e5e5fcdc430206d08119771a18977d3a476f4889e5fb6c6eb5fbdd6ab7519e66b096fdb53ae",
      "sequence": "ffffffff"
    },
    {
      "txid": "4ba60a7b2dc4ba89f10bb7939a9b8a6d6735642e655ca173625594432a006acd",
      "vout": "01000000",
      "scriptsigsize": "fd5e01",
      "scriptsig": "00493046022100b7aa571bfb81fa57e0d366f41be7e1d451fbf9529cbb5b5f0df3e2b9edc59ad6022100c02138c790e4c84288a7f9338f217a035fb87c4c0716c2dcc3d4a950704f323001473044022041c21d0fa28adeab92a355b285f62fdc2b1bee4f16b0d78aac0d3be2c6e986b102202e73c88015ae7966aa3fd0e06d7f0bb1d2e231c502ee333cd1f5f3c5f6f3a320014cc9524104a7a95441bb281f9f851556b8dcae7d5d85746e4382a852dcc8faa3a2320f442fed7d5b4f50d368cf4e18fb1642cfc4a5091e54d240aba9aeb74b07bcf95ad1d4410417b756f5562aa8b48d38fa25614391904dbfd7ef5a56e1d8b1e1c0b31200852a0ae3689350ed38be3d6de0c2472205f5ad697208784aa54174660cdf0b649b814104e35613163e133615ab272c30532c137f61344e14f36a146c3d4461863e5e5fcdc430206d08119771a18977d3a476f4889e5fb6c6eb5fbdd6ab7519e66b096fdb53ae",
      "sequence": "ffffffff"
    }
  ],
  "outputcount": "01",
  "outputs": [
    {
      "amount": "0000000000000000",
      "scriptpubkeysize": "00",
      "scriptpubkey": ""
    }
  ],
  "locktime": "00000000"
}

Transaction: 87d8ed6aae8ad82b01e2b9d7d7ca21e55e83e8fa2ae587892f12b06d3a12253c

This transaction has one output with an empty ScriptPubKey.

Normally this output would be spendable by anyone (because there's no lock on it), but the output amount is zero, so there's no value in spending it.

So basically this transaction gave all of the satoshis from the inputs away (100000 sats + 100000 sats) to the miner as a transaction fee.

Summary

This is Satoshi's explanation of why we use outputs in Bitcoin:

Although it would be possible to handle coins individually, it would be unwieldy to make a separate transaction for every cent in a transfer. To allow value to be split and combined, transactions contain multiple inputs and outputs. Normally there will be either a single input from a larger previous transaction or multiple inputs combining smaller amounts, and at most two outputs: one for the payment, and one returning the change, if any, back to the sender.
Satoshi Nakamoto, Bitcoin Whitepaper

So yeah, they're just small digital safe deposit boxes.