5

How many bytes does a P2PKH input have? I'm finding a few different numbers:

  • Why does the default miner implementation use pay-to-pubkey? states:

    push + sig + push + key = 1 + 72 + 1 + 61 = 139

  • Princeton Bitcoin Book states [p.123]:

    The approximate size of a transaction is 148 bytes for each input[…]

  • A knowledgeable Bitcoin developer calculated from the top of the mind for me over coffee:

    PREVOUT + SCRIPTSIG = 36 + (1 + 1 + 33 + 1 + (71 or 72)) = 143 or 144

I couldn't find further information in the Bitcoin Developer Guide or the wiki.

Bonus-question: How come there are different numbers? Did the size change over time?

8

The first number does not include the prevout, sequence number, or the length byte for the scriptSig. It also uses 65 bytes for the public key (which is correct if it is uncompressed, but compressed keys of 33 bytes are more common now). Correcting it gives 139 + 36 + 4 + 1 + (33 or 65) = 148 or 180.

The developer in the third case forgot to include the sequence number, making the result 147 or 148 for compressed public keys and 179 or 180 for uncompressed public keys.

The guys at Princeton clearly know best.

So to summarize:

PREVOUT: hash (32 bytes)
         index (4 bytes)
SCRIPTSIG: length (1 byte)
           CONTENTS: push opcode (1 byte)
                     signature (71 or 72 bytes)
                     push opcode (1 byte)
                     pubkey (33 bytes for compressed, 65 for uncompressed)
sequence (4 bytes)

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.