<p>Yes, your formula is correct for small counts of inputs and outputs of a single output-script type. Note that Bitcoin <a href="https://bitcoin.stackexchange.com/a/89418/5406">uses transaction weight (and/or vsize)</a> since segwit, but transaction weight is forward-compatible to transaction sizes of non-segwit transactions.</p>
<pre><code>tx_weight = overhead_weight + (input_weight × input_count) + (output_weight × output_count)
</code></pre>
<p>If you are only using P2PKH (legacy single-sig outputs) that is</p>
<pre><code>tx_vsize = 10 vB + (148 vB × input_count) + (34 vB × output_count)
</code></pre>
<p>If you have different output types, you will need to account for the <a href="https://bitcoin.stackexchange.com/q/84004/5406">different weights of outputs</a>: <a href="https://i.sstatic.net/CRkWw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CRkWw.png" alt="enter image description here" /></a></p>
<p>Also, if your input count or output count exceeds 254, you have to increase the size of the overhead because the respective counter will weigh 3 vB instead 1 vB.</p>

CC BY-SA 4.0
2023-02-16T15:03:28.303Z
thank you, so will just need to do some condition that will check if input_count > 254 || output_count > 254 and if so regularOverheadBytes will be 30 instead of 10 right? I do not use Segwit atm
Vladimir
CC BY-SA 4.0
2023-02-16T18:42:00.657Z
No, it would just be `+2 vB` per count that is greater than 254. What library are you using to build transactions? Usually they have functions to estimate transaction size.
Murch
CC BY-SA 4.0
2023-02-16T19:34:51.290Z
just realised they also have functions to estimate the fee for a transaction ...
Vladimir
CC BY-SA 4.0
2023-02-16T14:13:49.900Z
2023-02-16T18:41:04.160Z
2023-02-16T18:41:04.160Z
Murch
<p>Good morning, for the last few months I have been using the following formula to calculate transaction fee based on the transaction size when sending BTC from one address to multiple addresses(or batch transaction).
Currently I would like to reverse this and collect my BTC from multiple different addresses and send it to my cold wallet(which is one address that will purposely collect BTC). So instead of sending from 1 to many I would like to send BTC from many to 1.</p>
<pre><code> var transactionSizeBytes = _regularInputBytes + (countOfOutputsForThisTransactionWithoutChange * _regularOutputBytes) + (_regularOutputBytes/* bytes for change output*/) + _regularOverheadBytes;
            logger.LogInformation($&quot;Transaction size is : {transactionSizeBytes} bytes&quot;);
            logger.LogInformation($&quot;Transaction speed {_satoshiPerByteMedium} satoshi per byte &quot;);
            var transactionFeeSatoshi = transactionSizeBytes * _satoshiPerByteMedium;
            var transactionFeeBtc = transactionFeeSatoshi * _satoshiInBtc;
            return transactionFeeBtc;
</code></pre>
<p>This is the way I am calculating my fee and transaction size for the batch transaction 1 to many. I am assuming that if I want to instead send BTC from many to 1 the formula will be changed to:</p>
<pre><code>var transactionSizeBytes = (countOfInputsForThisTransactionWithoutChange * _regularInputBytes) + (_regularOutputBytes/* only one output for collection*/) + _regularOverheadBytes;
</code></pre>
<p>where countOfInputsForThisTransactionWithoutChange will be pretty much the count of addresses I want BTC to collect from.
Please correct me if this is wrong.</p>

<transactions><transaction-fees><transaction-weight>
Transfering btc from multiple btc addresses to a single btc address, estimating transaction size
Vladimir
# Transfering btc from multiple btc addresses to a single btc address, estimating transaction size

(Asked by: username_0 on 2023-02-16)

Good morning, for the last few months I have been using the following formula to calculate transaction fee based on the transaction size when sending BTC from one address to multiple addresses(or batch transaction).
Currently I would like to reverse this and collect my BTC from multiple different addresses and send it to my cold wallet(which is one address that will purposely collect BTC). So instead of sending from 1 to many I would like to send BTC from many to 1.

```
 var transactionSizeBytes = _regularInputBytes + (countOfOutputsForThisTransactionWithoutChange * _regularOutputBytes) + (_regularOutputBytes/* bytes for change output*/) + _regularOverheadBytes;
            logger.LogInformation($"Transaction size is : {transactionSizeBytes} bytes");
            logger.LogInformation($"Transaction speed {_satoshiPerByteMedium} satoshi per byte ");
            var transactionFeeSatoshi = transactionSizeBytes * _satoshiPerByteMedium;
            var transactionFeeBtc = transactionFeeSatoshi * _satoshiInBtc;
            return transactionFeeBtc;

```

This is the way I am calculating my fee and transaction size for the batch transaction 1 to many. I am assuming that if I want to instead send BTC from many to 1 the formula will be changed to:

```
var transactionSizeBytes = (countOfInputsForThisTransactionWithoutChange * _regularInputBytes) + (_regularOutputBytes/* only one output for collection*/) + _regularOverheadBytes;

```

where countOfInputsForThisTransactionWithoutChange will be pretty much the count of addresses I want BTC to collect from.
Please correct me if this is wrong.

**Tags:** transactions, transaction-fees, transaction-weight


---

## 1 answers

### Answer by username_1 on 2023-02-16. Score: 0 | Accepted answer

Yes, your formula is correct for small counts of inputs and outputs of a single output-script type. Note that Bitcoin [uses transaction weight (and/or vsize)](https://bitcoin.stackexchange.com/a/89418/5406) since segwit, but transaction weight is forward-compatible to transaction sizes of non-segwit transactions.

```
tx_weight = overhead_weight + (input_weight × input_count) + (output_weight × output_count)

```

If you are only using P2PKH (legacy single-sig outputs) that is

```
tx_vsize = 10 vB + (148 vB × input_count) + (34 vB × output_count)

```

If you have different output types, you will need to account for the [different weights of outputs](https://bitcoin.stackexchange.com/q/84004/5406): [![enter image description here](https://i.sstatic.net/CRkWw.png)](https://i.sstatic.net/CRkWw.png)

Also, if your input count or output count exceeds 254, you have to increase the size of the overhead because the respective counter will weigh 3 vB instead 1 vB.

> **Comments:**
> **username_0**: thank you, so will just need to do some condition that will check if input_count > 254 || output_count > 254 and if so regularOverheadBytes will be 30 instead of 10 right? I do not use Segwit atm  
> **username_1**: No, it would just be `+2 vB` per count that is greater than 254. What library are you using to build transactions? Usually they have functions to estimate transaction size.  
> **username_0**: just realised they also have functions to estimate the fee for a transaction ...  

---

