Bitcoin Forum
September 22, 2019, 06:54:32 AM
 News: If you like a topic and you see an orange "bump" link, click it. More info.
 Home Help Search Login Register More
 Pages: [1] 2  All
 Author Topic: How to calculate bitcoin transaction size and fees  (Read 302 times)
RapTarX
Full Member

Offline

Activity: 238
Merit: 155

PM me for Bounty Management

 May 06, 2019, 02:52:11 PMLast edit: May 06, 2019, 06:03:13 PM by RapTarXMerited by Pamoldar (4)

Bitcoin fees depend on the size of the transaction. For a bigger size of transaction, you must have to pay higher transaction fee. Here bigger size don't refer to the amount of the bitcoin to be transacted.

How to calculate transaction size
Source

Input*180 + output*34 + 10 plus or minus input
Say, input is 2 and output is to 3 address. The size is-
2*180 + 3*34 + 10 + or - 2 = 474/470bytes.

Output= number of addresses where you will send.

When input and output increase, the total size will also be increased which will cause you higher fee.

How to calculate fees
Now that the transaction size is calculated, check bitcoinfees and find out the current amount of satoshi per byte.
According to this site-
Quote
The fastest and cheapest transaction fee is currently 62 satoshis/byte
If someones pay 62 satoshi per byte, the transaction will likely to be listed in the next block, however, it's possible to pay less fee which will cause slow confirmation. If more fee is paid, the transaction process will be more faster.

1569135272
Hero Member

Offline

Posts: 1569135272

Ignore
 1569135272

1569135272
 Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1569135272
Hero Member

Offline

Posts: 1569135272

Ignore
 1569135272

1569135272
 Report to moderator
Bitcoin_Arena
Copper Member
Full Member

Offline

Activity: 336
Merit: 177

First 100% Liquid Stablecoin Backed by Gold

 May 06, 2019, 03:03:14 PM

I am a little confused on the output part.
Question is how do you come up with the output even before the transaction has been made since we are still trying to calculate the transaction fee?

RapTarX
Full Member

Offline

Activity: 238
Merit: 155

PM me for Bounty Management

 May 06, 2019, 03:07:04 PMMerited by Bitcoin_Arena (1)

I am a little confused on the output part.
Question is how do you come up with the output even before the transaction has been made since we are still trying to calculate the transaction fee?
Output means on how much addresses you are going to send. Generally, it should be 2 because if you send in one address, the change will be sent to another address of yourself. You may send 4 people at once (or more), the output will be 4+1=5 (if you send all the amount you have, no change will be made and total output will be 4 in that case). May be I'm wrong because I'm newbie in this space and trying to learn.
Edit-
Quote
The transaction output is the bitcoin address to which the money was sent.
Source- https://www.thebalance.com/how-does-a-bitcoin-transaction-work-391213

Therefore, it's known to us before transactions been made.

bitmover
Hero Member

Offline

Activity: 602
Merit: 1030

 May 06, 2019, 03:22:06 PMMerited by LoyceV (1), Pamoldar (1), DdmrDdmr (1), Bitcoin_Arena (1), RapTarX (1)

There is one important thing you forgot to mention.

What matters for fees is not how many addresses you have, but how many inputs you have.

Let´s suppose you engaged in many sig campaigns and you received 0,0005 every week for 20 weeks. You earned 0,01BTC, however you will have more than 20 inputs on the same address.

Every transaction made from your address will now have cost based on every input, individually, when you want to move them.

That´s why it´s important to consolidate your small inputs when fees are low.

If you consolidate your 20 0,0005 BTC with 2 sat/byte, it will be much cheaper than making a transaction now for 20 inputs with 60 sat/byte.

Take a look at LoyceV guide about it:
Fees are low, use this opportunity to Consolidate your small inputs!

RapTarX
Full Member

Offline

Activity: 238
Merit: 155

PM me for Bounty Management

 May 06, 2019, 03:32:04 PM

I had once seen this article but never tried to understand it. Thank you for breaking it down. Until now, I had misunderstanding about this. I guess now why it's important to consolidate all the input into one when fee is lower.
Corrected the OP.

Bitcoin_Arena
Copper Member
Full Member

Offline

Activity: 336
Merit: 177

First 100% Liquid Stablecoin Backed by Gold

 May 06, 2019, 04:35:40 PM

There is one important thing you forgot to mention.

What matters for fees is not how many addresses you have, but how many inputs you have.
I really had no idea that inputs can actually affect one's transaction fee.

Now back you your calculation @RapTarX
Code:
2*180 + 3*34 + 10 + or - 2 = 470/456 bytes.
we do see a +2 or -2 resulting into 470/456 bytes.

So which bytes do we consider? 470 or 456?
Or this is just a range where you can pick any value between 456 and 470 bytes and multiply with given rate which is currently 62sats/byte to get the total fees you have to pay?

Sorry for so many questions, I have been so reluctant in learning how to calculate these fees and this is an opportunity for me to know something

RapTarX
Full Member

Offline

Activity: 238
Merit: 155

PM me for Bounty Management

 May 06, 2019, 04:43:56 PM

So which bytes do we consider? 470 or 456?
Or this is just a range where you can pick any value between 456 and 470 bytes and multiply with given rate which is currently 62sats/byte to get the total fees you have to pay?
I guess it's a range. The size can be anywhere between those two however I'm not certain about this till now. Probably a senior member can confirm it.

Quote
Sorry for so many questions, I have been so reluctant in learning how to calculate these fees and this is an opportunity for me to know something
A simple suggestion-
Do query on here or google. Read article, share here whatever you have learnt. Community will correct you. This thread can be an example of that.

LoyceV
Legendary

Online

Activity: 1610
Merit: 4645

Largest Merit Circle on BPIP!

 May 06, 2019, 06:00:40 PMMerited by Pamoldar (1)

Input*180 + output*34 + 10 plus or minus input
Say, input is 2 and output is to 3 address. The size is-
2*180 + 3*34 + 10 + or - 2 = 470/456 bytes.
There's a much easier solution: use https://coinb.in/#fees, and in a few clicks you get the size including a recommended fee for a fast transaction. Note that most transactions don't need to be fast.

 ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀ .ChipMixer.{ MIXING REINVENTED FOR YOUR PRIVACY #.ChipMixer. ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀
RapTarX
Full Member

Offline

Activity: 238
Merit: 155

PM me for Bounty Management

 May 06, 2019, 06:04:23 PM

Input*180 + output*34 + 10 plus or minus input
Say, input is 2 and output is to 3 address. The size is-
2*180 + 3*34 + 10 + or - 2 = 470/456 bytes.
There's a much easier solution: use https://coinb.in/#fees, and in a few clicks you get the size including a recommended fee for a fast transaction. Note that most transactions don't need to be fast.
Thank you but it was an initiative of learning the process how it actually get done.

we do see a +2 or -2 resulting into 470/456 bytes.
It should be 474/470 bytes. My initial calculation was wrong. I guess you got it now.

john2231
Hero Member

Offline

Activity: 924
Merit: 1001

 May 06, 2019, 07:05:12 PM

Check this formula below I just got it from google when searching images.

Pamoldar
Legendary

Offline

Activity: 1246
Merit: 1347

KnowNoBorders.io

 May 06, 2019, 07:50:21 PM

There's a much easier solution: use https://coinb.in/#fees, and in a few clicks you get the size including a recommended fee for a fast transaction. Note that most transactions don't need to be fast.
Yes this site made me people lazy LOL (especially me). Until today I did not have this mind how byte size calculation works. All those days I only played with the sat/B field.

Thanks OP. It was useful more me 🙂 I left you some reward. Enjoy your 50 merit mark.

Quickseller
Copper Member
Legendary

Offline

Activity: 1904
Merit: 1746

 May 06, 2019, 08:14:01 PMMerited by bob123 (1)

Your formula is only accurate for non-segwit (and non-multisig) inputs.

A SegWit input will take up 91 bites and a bech32 input (a different type of SW address that starts with “BC1”) will take up 68 bites of block space after accounting for the witness (signature) discount.

Find the fire hydrant in my Avatar for a prize.
RapTarX
Full Member

Offline

Activity: 238
Merit: 155

PM me for Bounty Management

 May 06, 2019, 09:47:05 PM

Check this formula below I just got it from google when searching images.
I guess I too use this one as source in the OP, you probably have missed that part.

Thanks OP. It was useful more me 🙂 I left you some reward. Enjoy your 50 merit mark.
My pleasure. Thank you anyway.

Your formula is only accurate for non-segwit (and non-multisig) inputs.

A SegWit input will take up 91 bites and a bech32 input (a different type of SW address that starts with “BC1”) will take up 68 bites of block space after accounting for the witness (signature) discount.
Please link me toward the calculation of Segwit and bech32 segwit transaction size calculation. Interested to learn it.

Thirdspace
Hero Member

Offline

Activity: 1106
Merit: 717

Mixing reinvented for your privacy | chipmixer.com

 May 06, 2019, 10:50:54 PM

Your formula is only accurate for non-segwit (and non-multisig) inputs.

A SegWit input will take up 91 bites and a bech32 input (a different type of SW address that starts with “BC1”) will take up 68 bites of block space after accounting for the witness (signature) discount.
Please link me toward the calculation of Segwit and bech32 segwit transaction size calculation. Interested to learn it.

yes, your calculation works only for non-segwit inputs specifically utxo from uncompressed legacy addresses
for non-segwit compressed legacy you simply replace 180 with 148
checkout coinb.in's fee calculator that was mentioned by LoyceV in the post above
it should give you estimate size on almost all different possible inputs, except bech32

 ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀ .ChipMixer.{ MIXING REINVENTED FOR YOUR PRIVACY #.ChipMixer. ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀
pooya87
Legendary

Offline

Activity: 1764
Merit: 1884

Remember tonight for it's the beginning of forever

 May 07, 2019, 03:10:37 AMMerited by LoyceV (2), bitmover (1)

please don't create incomplete guides like this one here with a misleading formula. what you have found on the internet belongs to many years ago where bitcoin only had 1 type of transactions with 2 type of public keys (compressed and uncompressed) nowadays there are more variations and that formula is so complicated that you better leave it to your wallet to automatically calculate it for you.
of if you want to post a guide then do it completely by including all the possible cases with different types of input/output. and keep in mind that fees are no longer measured in satoshi/byte but instead in satoshi/virtualByte

also please don't suggest bitcoinfees.earn.com (https://bitcointalk.org/index.php?topic=2848987.msg30657510#msg30657510)

Now back you your calculation @RapTarX
Code:
2*180 + 3*34 + 10 + or - 2 = 470/456 bytes.
we do see a +2 or -2 resulting into 470/456 bytes.

it is because the day Satoshi created bitcoin he decided to use a third party library for signature stuff. this library is the OpenSSL library. there the encoding used for signatures is a wasteful and in one word stupid encoding for something like bitcoin.
to keep it simple here is how it works:
when you create an ECDSA signature you basically have 2 n-bits integers (256 bit for bitcoin's curve) in this particular encoding, on top of other wasted bytes you sometimes have to add an additional byte (=0) to the start of these integers to tell everyone reading the encoding that the numbers are positive. so sometimes you end up with
(some other bytes) + 1 + 32 + 1 + 32 or
(some other bytes) + 0 + 32 + 0 + 32 or
(some other bytes) + 1 + 32 + 0 + 32 or
(some other bytes) + 0 + 32 + 1 + 32
hence the +-2

which again brings us back to the first line of this comment! nowadays the second number is changed for some reasons (outside of the scope of this topic) so it will always be smaller than 32 byte. and there is a much newer change which also changes the first number so that it is 32 bytes (in some implementations such as bitcoin-core) so you will always end up with the same 32 byte size hence a fixed signature size.

 ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀ .ChipMixer.{ MIXING REINVENTED FOR YOUR PRIVACY #.ChipMixer. ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀
RapTarX
Full Member

Offline

Activity: 238
Merit: 155

PM me for Bounty Management

 May 07, 2019, 04:37:49 AM

please don't create incomplete guides like this one here with a misleading formula. what you have found on the internet belongs to many years ago where bitcoin only had 1 type of transactions with 2 type of public keys (compressed and uncompressed)
My bad, I am fairly new in this space and had no idea that fee can vary for legacy and segwit address. Had no idea for more input, I have to pay more fee. I got another thread about future fee of bitcoin transaction and this question peek at my mind that how fee is actually calculated. I was redirected to an article, was probably an old one which had referred to this method only.
Anyway, this is help and beginners board, beginners can do some mistakes. I guess members like you will always help beginners to understand the system, this is why a forum is the best place to learn.
Thank you.

pooya87
Legendary

Offline

Activity: 1764
Merit: 1884

Remember tonight for it's the beginning of forever

 May 07, 2019, 05:10:58 AMMerited by RapTarX (1)

please don't create incomplete guides like this one here with a misleading formula. what you have found on the internet belongs to many years ago where bitcoin only had 1 type of transactions with 2 type of public keys (compressed and uncompressed)
My bad, I am fairly new in this space and had no idea that fee can vary for legacy and segwit address. Had no idea for more input, I have to pay more fee. I got another thread about future fee of bitcoin transaction and this question peek at my mind that how fee is actually calculated. I was redirected to an article, was probably an old one which had referred to this method only.
Anyway, this is help and beginners board, beginners can do some mistakes. I guess members like you will always help beginners to understand the system, this is why a forum is the best place to learn.
Thank you.

it is not just legacy and SegWit, it is also compressed and uncompressed public keys and also multi signatures both in SegWit outputs (2 types) and in legacy outputs (1 type). which depending on their number of signers the size can be very different. before the year ends we may even see new signatures (Schnorr) and end up with a new transaction size based on them!

it is good to learn but it is best to try and post things as a question.

 ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀ .ChipMixer.{ MIXING REINVENTED FOR YOUR PRIVACY #.ChipMixer. ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀
bitmover
Hero Member

Offline

Activity: 602
Merit: 1030

 May 07, 2019, 10:11:33 AM

Thank you.

I think this will be great.

I did that with https://bitcointalk.org/index.php?topic=3317586.0

I read a lot about it and wrote. Then many users explained a lot of things to me that I wasn't aware and I updated it. Later on I read more about it and made new additions. You can do it here.

so far bitcoinfees.earn.com is inaccurate and leads to higher fees. coinb.in is better but i haven't checked it in long term to see how it performs under different circumstances.
I experienced this as well.

I usually search about 3-4 websites before making a transaction.  usually I use a lower value than suggested.

I noticed that Electrum suggests a fee as well when you are about to make a transaction (and they were lower than those websites).. Few months ago I made transactions with 1 sat/byte that wwere confirmed in less than 1hour, and most of those websites were suggesting more han 10sat/byte.

codehtcmail
Sr. Member

Offline

Activity: 854
Merit: 251

Tryig to survive in this harsh world

 May 07, 2019, 12:27:45 PM

I use Electrum and rarely use their suggested fees unless I am in a hurry.
I am sending bitcoins to myself from a non segwit to a segwit address and I paid only 5 sat/byte as I don't really care when it will get confirmed.
TryNinja
Legendary

Offline

Activity: 1134
Merit: 1469

 May 07, 2019, 12:36:15 PM

I use Electrum and rarely use their suggested fees unless I am in a hurry.
I am sending bitcoins to myself from a non segwit to a segwit address and I paid only 5 sat/byte as I don't really care when it will get confirmed.
It will get confirmed pretty soon. The mempool is pretty much empty and 1-3 blocks would clean it up to 2-3 sat/byte transactions.

I think this is the best website to visualize the state of the mempool and see that: https://jochen-hoenicke.de/queue/#1,2h

 ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀ .ChipMixer.{ MIXING REINVENTED FOR YOUR PRIVACY #.ChipMixer. ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀
 Pages: [1] 2  All