Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: NotATether on November 07, 2020, 07:17:34 AM



Title: How many bytes do additional inputs add to a transaction?
Post by: NotATether on November 07, 2020, 07:17:34 AM
On average, I would like to know by how many bytes does each input add to the transaction size, and whether larger inputs cause a larger byte count. I have a transaction that with 1 input and 2 outputs that is 200 bytes, and another with 5 inputs and 2 outputs with a size of 800 bytes, but I don’t think I can simply do a ratio calculation to get the average size.


Title: Re: How many bytes do additional inputs add to a transaction?
Post by: pooya87 on November 07, 2020, 07:45:45 AM
it depends on the output type that is being spent in your inputs!

each output has a locking script that requires an unlocking script in your input when you spend it. when the requirement for "unlocking" takes more space, the input can add more size to your final transaction.
for example your output could be a simple OP_TRUE and spending this requires no unlocking script so it only adds the fixed size of the outpoint (transaction hash and index) + sequence. or the output could be a very complex P2SH script that has OP_IF, OP_CheckMultiSig,... and the signature script could become a lot bigger.
in most cases you are either using P2PKH or P2WPKH and since these require a single public key + a single signature the script size is small.

there is also the matter of the difference between weight/virtual size and size. we no longer measure transaction sizes in raw bytes but instead in virtual bytes. essentially this means the legacy inputs result in a bigger virtual size than SegWit inputs which is why you end up paying less fee when using P2WPKH compared to P2PKH with the same number of inputs and outputs.

there is some tools that you can play around with input/output and visualize your transaction size/fees. there is  https://coinb.in/#fees and a new one by @bitmover (https://bitcointalk.org/index.php?topic=5281343.0) https://bitcoindata.science/bitcoin-fee-size-calculator.html you can check out.


Title: Re: How many bytes do additional inputs add to a transaction?
Post by: nc50lc on November 07, 2020, 08:23:47 AM
This approximation of the common inputs looks close enough: https://bitcoin.stackexchange.com/a/87276 (https://bitcoin.stackexchange.com/a/87276)
That's if you don't need the actual numbers, otherwise getting SegWit inputs' virtual size will be complicated (example (https://en.bitcoinwiki.org/wiki/Block_weight#Detailed_example)).


Title: Re: How many bytes do additional inputs add to a transaction?
Post by: HCP on November 07, 2020, 12:14:49 PM
Also, multisig can be a factor... if you have a 1-of-2, that'll result in smaller transaction that a 2-of-3 or a 3-of-5 etc... even if the number of inputs remains the same. The more signatures you need to add into a transaction, the larger it will grow.