<p><a href="https://bitcoin.stackexchange.com/a/3011/6288">Here</a> is a great answer on how to calculate the transaction size before sending. (Make sure to read the final edit.)</p>

<p>As for the fee, you've got it right: whatever amount from the inputs is NOT sent to other addresses, becomes the transaction fee for the miners.</p>

CC BY-SA 3.0
2013-09-17T15:26:44.497Z
Yes it exactly the same value size of transaction if we use bitcoind getrawtransaction command, e.g.
bitcoind getrawtransaction d9804de366aa4c2a01565c3a3c8aa2ea20baafc276dc875f80b9044841205333 
return 15522 length of hex-string, so in real bytes it will be 7761 whcih is actual size of transaction
Arsenius
CC BY-SA 3.0
2013-09-17T14:31:31.483Z
2013-09-17T14:31:31.483Z
2017-04-13T12:47:32.940Z
timetofly
<p>So, after understanding how to create and send raw transactions on the basis of <a href="https://bitcoin.stackexchange.com/questions/13332/how-to-send-from-many-bitcoin-addresses-to-one-bitcoin-address">'How to send from many bitcoin addresses to one bitcoin address?'</a>, in practice I still struggle with transaction fees. For example, I do the following in order to calculate the size of an hex-encoded transaction:</p>

<pre><code>hex_raw_transaction = createrawtransaction(...)
hex_raw_transaction = signrawtransaction(hex_raw_transaction)
byte[] size = HexStringToByteArray(hex_raw_transaction)
int transaction_size = size.Length
</code></pre>

<p>Is that a correct way to determinate the transaction size? (Regarding to <a href="https://en.bitcoin.it/wiki/Transaction_fees" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Transaction_fees</a>)? </p>

<p>Is it correct that the transaction fee is set by the unassigned amount in the outputs?</p>

<p>For example, if I have 1 BTC in one address and send the 0.65 BTC to a second address and 0.3495 BTC as change to the first</p>

<pre><code>//The fee will be: 
fee = 1 - (0.65 + 0.3495)  //= 0.0005 btc
</code></pre>

<p>is it correct that the fee will be 0.0005 BTC? </p>

<transaction-fees><raw-transaction>
How are transaction fees calculated in raw-transactions?
Arsenius
# How are transaction fees calculated in raw-transactions?

(Asked by: username_0 on 2013-09-17)

So, after understanding how to create and send raw transactions on the basis of 'How to send from many bitcoin addresses to one bitcoin address?', in practice I still struggle with transaction fees. For example, I do the following in order to calculate the size of an hex-encoded transaction:
hex_raw_transaction = createrawtransaction(...)
hex_raw_transaction = signrawtransaction(hex_raw_transaction)
byte[] size = HexStringToByteArray(hex_raw_transaction)
int transaction_size = size.Length

Is that a correct way to determinate the transaction size? (Regarding to https://en.bitcoin.it/wiki/Transaction_fees)? 
Is it correct that the transaction fee is set by the unassigned amount in the outputs?
For example, if I have 1 BTC in one address and send the 0.65 BTC to a second address and 0.3495 BTC as change to the first
//The fee will be: 
fee = 1 - (0.65 + 0.3495)  //= 0.0005 btc

is it correct that the fee will be 0.0005 BTC?

**Tags:** transaction-fees, raw-transaction


---

## 1 answers

### Answer by username_1 on 2013-09-17. Score: 2

[Here](https://bitcoin.stackexchange.com/a/3011/6288) is a great answer on how to calculate the transaction size before sending. (Make sure to read the final edit.)

As for the fee, you've got it right: whatever amount from the inputs is NOT sent to other addresses, becomes the transaction fee for the miners.

> **Comments:**
> **username_0**: Yes it exactly the same value size of transaction if we use bitcoind getrawtransaction command, e.g. bitcoind getrawtransaction d9804de366aa4c2a01565c3a3c8aa2ea20baafc276dc875f80b9044841205333  return 15522 length of hex-string, so in real bytes it will be 7761 whcih is actual size of transaction  

---

