<p>Transactions compete with each other in regard to the fee they offer to the miner divided by the amount of blockspace they require to be included in a block.</p>

<h2>Where does the fee come from?</h2>

<p>When you craft a transaction, you first determine the amount that you want to send. After creating the sending outputs, you collect inputs that have sufficient value to pay for the sending outputs as well as that. Your software then crafts a payment order (transaction) that lists the inputs to be consumed authenticated by the corresponding signatures, as well as the outputs to be created. If the inputs total value exceeds what you wanted to send, you will often create an additional change output to send back the remainder to an address that you control.<br>
 Obviously, you may not create outputs worth more than the inputs that you spend, but the opposite is required: The difference between the sum of the inputs and the sum of the outputs, i.e. the value that you have not reassigned to a recipient, is free-floating and may be collected by the miners in the coinbase transaction of the confirming block.</p>

<h2>How big is a transaction?</h2>

<p>The amount of blockspace required, is dependent on the type of script that you use in your input. e.g.:</p>

<ul>
<li>a P2PKH input has 147 or 148 bytes</li>
<li>a P2SH 2 of 3 multisignature input has 295 bytes</li>
<li>variable for custom P2SH scripts</li>
</ul>

<p>As far as I know, all outputs right now are 34 bytes.</p>

<p>To calculate the whole transaction size, you add up the transaction header (10 bytes), the inputs with their corresponding size (n*148 bytes for P2PKH), and the outputs (m*34 bytes).</p>

<h2>Fee Rate</h2>

<p>The fee rate is now the amount of freefloating fee in satoshis per the size of the transaction in bytes:</p>

<pre><code>feeRate [sat/byte] = fee [sat] / txsize [byte]
</code></pre>

<p>Miners will generally select transactions by order of highest fee rate first.</p>

CC BY-SA 3.0
2017-07-02T15:58:53.040Z
2017-07-02T15:58:53.040Z
Murch
<p>Some says that transaction fee is calculated based on the size of transactions. </p>

<p>In short, does it mean based on the number of utxos? To be precise, does it mean depending on the size of all of input scripts and output scripts? I know senders can set the fee as they like. But usually bitcoin users don't do that, just use wallet app, so this question is about general cases.</p>

<p>e.g. transaction (A) fee is cheaper than (B) because of the I/O scripts size.</p>

<p>(A) <a href="https://blockchain.info/ja/tx/6687d3e1c48901f6571ea70e2a94175af993fd934d51b82b5eb20a93d2dd98cf" rel="noreferrer">https://blockchain.info/ja/tx/6687d3e1c48901f6571ea70e2a94175af993fd934d51b82b5eb20a93d2dd98cf</a></p>

<p>(B) <a href="https://blockchain.info/en/tx/31b36d45323a8dd4b33832c561c8e5d8703c324ee5850924f20373222e80b529" rel="noreferrer">https://blockchain.info/en/tx/31b36d45323a8dd4b33832c561c8e5d8703c324ee5850924f20373222e80b529</a> </p>

<p>My question is whether another factor affects the price of the fee or not.</p>

<transactions><transaction-fees>
How is transaction fee calculated?
zono
# How is transaction fee calculated?

(Asked by: username_0 on 2016-03-02)

Some says that transaction fee is calculated based on the size of transactions.

In short, does it mean based on the number of utxos? To be precise, does it mean depending on the size of all of input scripts and output scripts? I know senders can set the fee as they like. But usually bitcoin users don't do that, just use wallet app, so this question is about general cases.

e.g. transaction (A) fee is cheaper than (B) because of the I/O scripts size.

(A) <https://blockchain.info/ja/tx/6687d3e1c48901f6571ea70e2a94175af993fd934d51b82b5eb20a93d2dd98cf>

(B) <https://blockchain.info/en/tx/31b36d45323a8dd4b33832c561c8e5d8703c324ee5850924f20373222e80b529>

My question is whether another factor affects the price of the fee or not.

**Tags:** transactions, transaction-fees


---

## 1 answers

### Answer by username_1 on 2017-07-02. Score: 4

Transactions compete with each other in regard to the fee they offer to the miner divided by the amount of blockspace they require to be included in a block.

## Where does the fee come from?

When you craft a transaction, you first determine the amount that you want to send. After creating the sending outputs, you collect inputs that have sufficient value to pay for the sending outputs as well as that. Your software then crafts a payment order (transaction) that lists the inputs to be consumed authenticated by the corresponding signatures, as well as the outputs to be created. If the inputs total value exceeds what you wanted to send, you will often create an additional change output to send back the remainder to an address that you control.  
Obviously, you may not create outputs worth more than the inputs that you spend, but the opposite is required: The difference between the sum of the inputs and the sum of the outputs, i.e. the value that you have not reassigned to a recipient, is free-floating and may be collected by the miners in the coinbase transaction of the confirming block.

## How big is a transaction?

The amount of blockspace required, is dependent on the type of script that you use in your input. e.g.:

* a P2PKH input has 147 or 148 bytes
* a P2SH 2 of 3 multisignature input has 295 bytes
* variable for custom P2SH scripts

As far as I know, all outputs right now are 34 bytes.

To calculate the whole transaction size, you add up the transaction header (10 bytes), the inputs with their corresponding size (n\*148 bytes for P2PKH), and the outputs (m\*34 bytes).

## Fee Rate

The fee rate is now the amount of freefloating fee in satoshis per the size of the transaction in bytes:

```
feeRate [sat/byte] = fee [sat] / txsize [byte]

```

Miners will generally select transactions by order of highest fee rate first.


---

