Making Sense of Bitcoin Transaction Fees
Every Bitcoin transaction is subject to a fee paid by the sender. In contrast to bank fees charged at either a flat rate or as a percentage of transaction value, Bitcoin fees are based on the amount of data needed for encoding. Understanding this system is not difficult, but its nuances and non-intuitive nature confuse many Bitcoin users, new and experienced alike.
Understanding transaction fees can save you both money and time. This guide describes how the Bitcoin transaction fee system works and how to use it effectively.
An Expensive Payment
Fees usually account for a small share of a Bitcoin transaction. But sometimes a fee can approach or even exceed the amount being transferred. Let's consider a hypothetical case in which transaction fees seem to go haywire.
Alice runs a successful blog. At the end of each post, she displays a QR code to accept Bitcoin donations. Once every month, Alice sweeps the accumulated balance from the donation address into her Electrum wallet. A fee of about 1.5% is usually needed.
One month Alice receives hundreds of small donations, an unusually high number. Unlike previous transfers, this one seems to require a fee of 30%. Why did this happen?
Like Alice, you may notice surprisingly high transaction fees in any of these situations:
- you publish an address used for collecting donations
- your wallet is old an you've made many payments
- you frequent online gaming sites that make large numbers of small payouts
- you use sites giving out free bitcoin
- you participate in a mining pool
- you run a website generating affiliate revenue
Bitcoin is an Electronic Cash System
Satoshi Nakamoto described Bitcoin as an “electronic cash system”. The distinction between a cash system and a credit or online banking system may not seem important at the moment. However, the first step toward understanding Bitcoin transaction fees is to forget what you know about these other payment methods.
Imagine keeping track of different pools of paper bills, maybe as part of a charity drive. You might use envelopes to organize donations you receive. The cash each donor sends would be placed into a paper envelope (a “cash envelope”), to be counted and redistributed into new envelopes later.
At a high level, Bitcoin can be thought of as an electronic version of this cash envelope system. An address holds zero or more units of electronic cash in specific denominations. Incoming payments add cash units (and value) to an address. Outgoing payments remove cash units (and value).
Bitcoin uses the term “unspent output” to refer to its units of electronic cash. The term originates from deep within the Bitcoin technical specification. Fortunately, it's not necessary to understand the details. For now, when you see the term “unspent output”, picture a paper bill having a fixed denomination.
All Transactions are Not Created Equal
A Bitcoin transaction reassigns ownership of one or more unspent outputs. Perhaps counterintuitively, fees are based on the total number of unspent outputs the transaction reassigns, not on their combined value.
Imagine that Bob controls a Bitcoin address to which a single payment in the amount of 1 bitcoin (BTC) has been made. When he buys a t-shirt costing 6 mBTC online, his transaction fee is 0.1 millibitcoins (mBTC), or 1.7%.
Like Bob, Alice controls a Bitcoin address valued at 1 BTC. However, Alice has received thousands of small payments to arrive at this balance. When Alice buys the same t-shirt as Bob for 6 mBTC, she pays a fee of 0.4 mBTC, or 6.7%.
Alice and Bob each start with a wallet valued at 1 BTC and buy the same item for the same price. Yet Bob pays a fee of 1.7% while Alice pays a fee of 6.7%. Is this fair?
Transactions are represented as a blobs of digital data not unlike images or other files on your computer. Files containing more content take up more disk space and require more network bandwidth to transfer. Similarly, Bicoin transactions that reassign more unspent outputs require more data and therefore more resources to validate and archive.
Alice pays a higher fee because the data requirements of her transaction place a heavier burden on the network's storage and bandwidth resources.
Our mental model of transactions reassigning unspent outputs is accurate, but incomplete. An unspent output from one transaction can serve as an input to another transaction, resulting in a chain of transactions, with each member transferring control of a currency unit to the one after it. A single Bitcoin transaction can transfer funds to one or more addresses.
Both inputs and outputs contribute to the amount of data contained in a transaction, and ultimately the fee.
Estimating Transaction Fees
As reported in the Bitcoin Wiki, every 1,000 bytes of data in a transaction adds 0.1 mBTC to the fee. Any size below an even thousand is rounded up to the nearest thousand. For example, the fee on a 675-byte transaction would be 0.1 mBTC. Likewise, the fee on a 1,345-byte transaction would be 0.2 mBTC.
To estimate a fee, we need a way to relate the number of transaction inputs (in) and outputs (out) to its size in bytes (size). The exact size of a transaction can only be determined after it has been signed, which is unfortunately too late to be of much use in many wallet programs. However, the upper size limit can be found with this equation:
size = 181 * in + 34 * out + 10
A typical transaction requires two outputs - one for the payee and one for receiving change. Using the above formula as a starting point we can see that the maximum number of inputs this kind of transaction can use and still expect to pay a 0.1 mBTC fee is five.
This fee would double to 0.2 mBTC by the addition of just one more input. An additional eleven inputs would double the fee again to 0.4 mBTC.
Minimizing Transaction Fees
Transaction fees may be minimized in two ways: (1) by minimizing the number of small inputs; and (2) by reducing the cost of using each input. Both approaches are viable and can be effectively combined.
The easiest way to reduce the number of small inputs in a wallet is to avoid receiving them in the first place. If you're currently paid many times with small amounts, consider asking for fewer, larger payments instead.
If you don‘t control the number of payment you receive, for example because you’ve posted a donation address online, your wallet software may make the right decisions about selecting inputs for you. If it doesn't and you feel that fees are still too high, consider a wallet supporting coin control.
Bitcoin Core now offers a handy coin control feature. To access it, choose the “Display” option from the Options screen and check the “Display coin control features” box.
With the coin control option selected, Bitcoin core allows you to choose the inputs for any transaction by clicking the “Inputs” button from the Send screen. This may be helpful when consolidating large numbers of small payments.
In addition to reducing the number of transaction inputs, reducing the data requirements for each input can also reduce fees. Compressed public keys make this possible by reducing the per-input byte requirement from 180 to 148. For a typical transaction with two outputs, compressed public keys lead to a size reduction large enough to accomodate six inputs for a 0.1 mBTC fee, compared to the five inputs available with an uncompressed public key address.
To find out if your wallet uses public key compression, examine the Wallet Import Format (WIF) of your private keys. WIF-encoded private keys beginning with the number “5” indicate uncompressed public keys, and those beginning with the letters “K” or “L” indictate compressed public keys.
Fees are Waived for Some Transactions
Some transactions qualify for a fee waiver. According to the Wiki, a transaction may be reliably sent without a fee if all of these conditions are met:
- it is smaller than 1,000 bytes
- all outputs are greater than 10 mBTC in value
- all inputs are of sufficient value and age
These restrictions are aimed at preventing low value “spam” transactions released by malicious users trying to interfere with the network. The last requirement enables high-value transactions to be sent without a fee given that enough time passes between transactions. This requirement is termed “priority”, and may be calculated as:
priority = sum(input_value_in_base_units * input_age)/size_in_bytes
input_value_in_base_units is the value of each input expressed in satoshis (one bitcoin is equivalent to 100,000,000 satoshis),
input_age is the number of confirmations each input has received, and
size_in_bytes is the size of the transaction in bytes. Transactions with a priority greater than 57.6 million can qualify for zero-fee transactions.
Rearranging the priority calculation and combining it with the equation to estimate transaction size, we can find out how long to wait before sending a zero-fee transaction using a single input and two outputs:
input_age = (57,600,000 * (181 + 34 * 2 + 10)) / input_value_in_base_units
Imagine that Alice controls an address containing one unspent input valued at 100 mBTC. To be allowed to spend funds without a transaction fee, she would need to wait:
(57,600,000 * (181 + 34 * 2 + 10)) / 10,000,000
or 1,492 confirmations. Given that the network produces roughly 144 confirmations per day, Alice should wait at least 10 days. Using a receiving address derived from a compressed public key would cut the wait time to nine days. Likewise, wait time could be cut to 5 days by doubling the value of the input to 200 mBTC.
As a rule of thumb, a single bitcoin output can be spent without a fee one day after receiving it.
Real Networks Have Exceptions
The rules for transaction fees presented here have been compiled from documentation. However, nothing forces any miner or mining pool to abide by them. A small contingent of mining pools accept any valid transaction, regardless of fee or size. Because the combined hash power of these miners accounts for a small percentage of the total network capacity, zero-fee transactions may eventually be confirmed, albeit at a very slow rate. Sometimes this rate is so low that a non-qualifying zero-fee transaction disappears from the network without being confirmed.
If you decide to ride cheap, expect to be delayed.
Bitcoin transaction fees may seem arbitrary at first, but they actually follow well-defined rules:
- Bitcoin is a digital cash system. The electronic equivalent of a paper bill is an “unspent output”. Unspent outputs from one transaction become inputs into the next transaction, and so on.
- The network levies a fee based on the size of a transaction in bytes, not its monetary value.
- The single biggest contributor to overall transaction size (and therefore cost) is the number of inputs.
- Spending from addresses that have received large numbers of small payments can result in surprisingly high fees.
- Coin control can be helpful in consolidating large numbers of unspent outputs received from tipping and other small payments.
- The equivalent of one bitcoin held for one day can be reliably spent without a transaction fee.
Image credits: Wikipedia; Cory Checketts; Mike Fleming