<pre><code>pubkeySize=33
sigSize=72


SizeOfRedeemScript = 1+n*pubkeySize+1+1
SizeOfScriptSig = 1+m*(1+sigSize)+SizeOfVarIntFor(RedeemScript)+SizeOfRedeemScript
sizeOf(input) = 32+4+SizeOfVarIntFor(SizeOfScriptSig) + SizeOfScriptSig + 4

SizeOfScriptPubKey = SizeOfVarIntFor(SizeOfRedeemScript) + len(script)
sizeOf(output) = 8 + SizeOfScriptPubKey

sizeOf(tx) = 4 + SizeOfVarIntFor(numInputs) + sum(SizeOfInputsArray) + SizeOfVarIntFor(numOutputs) + sum(SizeOfOutputsArray) + 4
</code></pre>

<p>Basically, once you know m &amp; n (for your multisig), whether public keys are compressed (pubkeySize), plus the number of inputs and outputs, plus the types of outputs, you can come up with a pretty accurate figure for the size. </p>

CC BY-SA 3.0
2017-08-02T18:25:16.540Z
I've added "sum(SizeOfOutputsArray)" to the last line, because it seemed to be missing.
Murch
CC BY-SA 3.0
2017-08-30T16:06:04.283Z
@karimkorun what means `SizeOfVarIntFor`
Goko Gorgiovski
CC BY-SA 3.0
2018-01-14T22:20:02.707Z
https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer it's documented here. scripts and vectors are both data-types with variable length, so we prefix them with the length the parser should try to read. They have variable size also, and so are relevant to size estimation :)
karimkorun
CC BY-SA 4.0
2018-12-26T19:15:45.160Z
what is `len(script)` here ? should `SizeOfVarIntFor(RedeemScript)` be `SizeOfVarIntFor(SizeOfRedeemScript)` ? is `lengthOfScript` the same as `SizeOfScriptSig`? If not, how is `lengthOfScript` generated?
tipu
CC BY-SA 4.0
2020-01-05T07:25:55.997Z
These equations are very incomplete, ambiguous, and inconsistent, as others have mentioned. What is `len(script)`? Downvoted.
B T
CC BY-SA 4.0
2020-01-16T16:52:45.090Z
len(script) is the length of the script.. in bytes..

@BT - it's pseudocode. it's not supposed to be complete.

Here's an implementation I wrote, using exactly these functions https://github.com/blocktrail/blocktrail-sdk-php/blob/master/src/SizeEstimation.php
karimkorun
CC BY-SA 4.0
2020-01-16T16:56:07.127Z
@tipu
Yes! edited. thanks!
karimkorun
CC BY-SA 4.0
2017-04-11T15:08:41.027Z
2020-01-16T16:56:40.233Z
2020-01-16T16:56:40.233Z
karimkorun
<p>I stepped over this while trying to solve a similiar question: "how much tx fees do I need to prepare?"... Though this is an older question, I thought it would be good still be ok to reply, so that others might benefit from the same research. </p>

<p><a href="https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm</a></p>

<p>... Signatures are either 73, 72, or 71 bytes long, with probabilities approximately 25%, 50% and 25% respectively, although sizes even smaller than that are possible with exponentially decreasing probability.</p>

<p>Behind the Sigs there is normally the pubkey in hex, adding 33 Bytes for compressed, and 65 Bytes for uncompressed keys. So I calculate for a standard TX roughly 100 Bytes per sig. 
You already have your figures for inputs and outputs. My std 2 inputs/2 outputs TX is roughly 400Bytes. 
The Inputs part of a TX depends on the number of </p>

CC BY-SA 3.0
2017-07-10T19:27:11.713Z
Since the low-S rules was introduced, signature are 50% of the time 72 bytes and 50% of the time 71.
Pieter Wuille
CC BY-SA 3.0
2017-04-10T08:50:02.207Z
2017-04-10T08:50:02.207Z
pebwindkraft
<p>I wrote some code to calculate an estimate for multisig transaction size based on Karimkorun's almost unreadable answer and based off the (incomplete) <a href="https://en.bitcoin.it/wiki/Protocol_documentation#tx" rel="nofollow noreferrer">documentation here</a>.</p>

<p>The code:</p>

<pre><code>var pubkeySize = 33
var sigSize = 72
// An approximation based on the example in
// https://en.bitcoin.it/wiki/Protocol_documentation#tx
var pubkeyScriptSize = 25 

var m = 2, n = 3

var result = tx([input(m,n)], [output(1,1), output(m,n)])
console.log(result)


// All functions calculate sizes

function input(m, n) {
  var outpoint = 32 + 4
  var sequence = 4
  return outpoint + varIntAndValue(sigScript(m, n)) + sequence
}
function sigScript(m, n) {
  return 1 + m * (1 + sigSize) + varIntAndValue(redeemScript(n))
}
function redeemScript(n) {
  return 1 + n * pubkeySize + 1 + 1
}

function output(m, n) {
  var outputValue = 8
  return outputValue + pubkeyScript(m, n)
}
function pubkeyScript(m, n) {
  return varIntAndValue(pubkeyScriptSize)
}

function tx(inputs, outputs) {
  var versionSize = 4
  var lockTime = 4
  return versionSize + varInt(inputs.length) + sum(inputs)
       + varInt(outputs.length) + sum(outputs) + lockTime
}

// The size of a variable integer for the given value.
// See https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
function varInt(value) {
  if (value &lt; 0xFD) {
    return 1
  } else if (value &lt;= 0xFFFF) {
    return 3
  } else if (value &lt;= 0xFFFFFFFF) {
    return 5
  } else {
    return 9
  }
}
function varIntAndValue(value) {
  return varInt(value) + value    
}
function sum(list) {
  return list.reduce((acc, x) =&gt; acc + x, 0) 
}
</code></pre>

CC BY-SA 4.0
2020-01-05T07:37:54.207Z
2020-01-05T07:37:54.207Z
B T
<p>I was looking for answer everywhere.
Basically is there any way of calculate multi-sig transaction size when the transaction is creating, before the signing procedure? I was trying to find any pattern for that, with no results.</p>

<p>Informations I have:</p>

<ul>
<li>num of inputs;</li>
<li>num of outputs;</li>
<li>num of required signatures</li>
</ul>

<p>I will appreciate any clue to solve this problem.</p>

CC BY-SA 3.0
2014-09-18T14:19:23.517Z
Are you asking about transactions with several inputs or about input/output from/to msig-address?
amaclin
CC BY-SA 3.0
2014-09-18T14:57:24.770Z
About transaction from multisig address. So I have few transactions belonging to multisig address and I want to send money to whatever address. Before broadcast to the network multisig transaction require signing, in my case two signatures. The base transaction after calling './bitcoin-cli createrawtransaction trans_list recipients' is quite small, after first sign becoming around 1000 bytes and after second 2000 bytes it also depending from how many transactions is coming as input
Mr.Coffee
CC BY-SA 3.0
2014-09-18T15:00:37.023Z
OK, next question is: bare multisig output or p2sh multisig?
amaclin
CC BY-SA 3.0
2014-09-18T15:11:54.337Z
It is p2sh script, created by './bitcoin-cli createmultisig <num required> <addresses|pubkeys>'
Mr.Coffee
<transaction-fees><multi-signature>
Predict multi signature transaction size
Mr.Coffee
# Predict multi signature transaction size

(Asked by: username_0 on 2014-09-18)

I was looking for answer everywhere.
Basically is there any way of calculate multi-sig transaction size when the transaction is creating, before the signing procedure? I was trying to find any pattern for that, with no results.

Informations I have:

* num of inputs;
* num of outputs;
* num of required signatures

I will appreciate any clue to solve this problem.

**Tags:** transaction-fees, multi-signature

> **Comments:**
> **username_1**: Are you asking about transactions with several inputs or about input/output from/to msig-address?  
> **username_0**: About transaction from multisig address. So I have few transactions belonging to multisig address and I want to send money to whatever address. Before broadcast to the network multisig transaction require signing, in my case two signatures. The base transaction after calling './bitcoin-cli createrawtransaction trans_list recipients' is quite small, after first sign becoming around 1000 bytes and after second 2000 bytes it also depending from how many transactions is coming as input  
> **username_1**: OK, next question is: bare multisig output or p2sh multisig?  
> **username_0**: It is p2sh script, created by './bitcoin-cli createmultisig <num required> <addresses|pubkeys>'  

---

## 3 answers

### Answer by username_2 on 2017-04-11. Score: 2

```
pubkeySize=33
sigSize=72

SizeOfRedeemScript = 1+n*pubkeySize+1+1
SizeOfScriptSig = 1+m*(1+sigSize)+SizeOfVarIntFor(RedeemScript)+SizeOfRedeemScript
sizeOf(input) = 32+4+SizeOfVarIntFor(SizeOfScriptSig) + SizeOfScriptSig + 4

SizeOfScriptPubKey = SizeOfVarIntFor(SizeOfRedeemScript) + len(script)
sizeOf(output) = 8 + SizeOfScriptPubKey

sizeOf(tx) = 4 + SizeOfVarIntFor(numInputs) + sum(SizeOfInputsArray) + SizeOfVarIntFor(numOutputs) + sum(SizeOfOutputsArray) + 4

```

Basically, once you know m & n (for your multisig), whether public keys are compressed (pubkeySize), plus the number of inputs and outputs, plus the types of outputs, you can come up with a pretty accurate figure for the size.

> **Comments:**
> **username_3**: I've added "sum(SizeOfOutputsArray)" to the last line, because it seemed to be missing.  
> **username_4**: @username_2 what means `SizeOfVarIntFor`  
> **username_2**: https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer it's documented here. scripts and vectors are both data-types with variable length, so we prefix them with the length the parser should try to read. They have variable size also, and so are relevant to size estimation :)  
> **username_5**: what is `len(script)` here ? should `SizeOfVarIntFor(RedeemScript)` be `SizeOfVarIntFor(SizeOfRedeemScript)` ? is `lengthOfScript` the same as `SizeOfScriptSig`? If not, how is `lengthOfScript` generated?  
> **username_6**: These equations are very incomplete, ambiguous, and inconsistent, as others have mentioned. What is `len(script)`? Downvoted.  
> **username_2**: len(script) is the length of the script.. in bytes..  @BT - it's pseudocode. it's not supposed to be complete.  Here's an implementation I wrote, using exactly these functions https://github.com/blocktrail/blocktrail-sdk-php/blob/master/src/SizeEstimation.php  
> **username_2**: @username_5 Yes! edited. thanks!  

---

### Answer by username_7 on 2017-04-10. Score: 0

I stepped over this while trying to solve a similiar question: "how much tx fees do I need to prepare?"... Though this is an older question, I thought it would be good still be ok to reply, so that others might benefit from the same research.

<https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm>

... Signatures are either 73, 72, or 71 bytes long, with probabilities approximately 25%, 50% and 25% respectively, although sizes even smaller than that are possible with exponentially decreasing probability.

Behind the Sigs there is normally the pubkey in hex, adding 33 Bytes for compressed, and 65 Bytes for uncompressed keys. So I calculate for a standard TX roughly 100 Bytes per sig.
You already have your figures for inputs and outputs. My std 2 inputs/2 outputs TX is roughly 400Bytes.
The Inputs part of a TX depends on the number of

> **Comments:**
> **username_8**: Since the low-S rules was introduced, signature are 50% of the time 72 bytes and 50% of the time 71.  

---

### Answer by username_6 on 2020-01-05. Score: 0

I wrote some code to calculate an estimate for multisig transaction size based on username_2's almost unreadable answer and based off the (incomplete) [documentation here](https://en.bitcoin.it/wiki/Protocol_documentation#tx).

The code:

```
var pubkeySize = 33
var sigSize = 72
// An approximation based on the example in
// https://en.bitcoin.it/wiki/Protocol_documentation#tx
var pubkeyScriptSize = 25 

var m = 2, n = 3

var result = tx([input(m,n)], [output(1,1), output(m,n)])
console.log(result)

// All functions calculate sizes

function input(m, n) {
  var outpoint = 32 + 4
  var sequence = 4
  return outpoint + varIntAndValue(sigScript(m, n)) + sequence
}
function sigScript(m, n) {
  return 1 + m * (1 + sigSize) + varIntAndValue(redeemScript(n))
}
function redeemScript(n) {
  return 1 + n * pubkeySize + 1 + 1
}

function output(m, n) {
  var outputValue = 8
  return outputValue + pubkeyScript(m, n)
}
function pubkeyScript(m, n) {
  return varIntAndValue(pubkeyScriptSize)
}

function tx(inputs, outputs) {
  var versionSize = 4
  var lockTime = 4
  return versionSize + varInt(inputs.length) + sum(inputs)
       + varInt(outputs.length) + sum(outputs) + lockTime
}

// The size of a variable integer for the given value.
// See https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
function varInt(value) {
  if (value < 0xFD) {
    return 1
  } else if (value <= 0xFFFF) {
    return 3
  } else if (value <= 0xFFFFFFFF) {
    return 5
  } else {
    return 9
  }
}
function varIntAndValue(value) {
  return varInt(value) + value    
}
function sum(list) {
  return list.reduce((acc, x) => acc + x, 0) 
}

```


---

