BTC - How Fee Estimate Works

Bitcoin (BTC) operates on a UTXO (Unspent Transaction Output) model, where the transaction fee is estimated based on two primary parameters:

  1. Approximate fee per kilobyte
  2. Transaction size

BTC Fee Estimate Formula

The Formula

Estimated Fee == "approximate fee per kilobyte" x "transaction size"

Step_1: Calculating the Approximate Fee per Kilobyte

To estimate the fee for a BTC transaction, you can use the Tatum endpoint for BTC "fee estimate":

Example request:

curl --location 'https://api.tatum.io/v3/blockchain/fee/BTC' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data ''
//Response:
{
    "fast": 13.5, // Satoshis per byte == 0.0135 satoshis per kilobyte.
    "medium": 5,
    "slow": 4,
    "block": 813488, //Last block used to calculate fee
    "time": "2023-10-23T12:14:42.817Z" // Last calculation timestamp
}

Alternatively, you can make an RPC node request:

Example request:

curl --location 'https://api.tatum.io/v3/blockchain/node/BTC/' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
    "jsonrpc":"1.0",
    "id":"curltext",
    "method":"estimatesmartfee",
    "params":[2] // specifies the target confirmation time in blocks.
//response:
{
    "result": {
        "feerate": 0.00001, // Satoshis per Kilobyte
        "blocks": 2
    },
    "error": null,
    "id": "curltext"
}

Step_2: Calculating the Transaction Size

Transaction Size (in bytes) = (Number of Inputs x 148) + (Number of Outputs x 34) + 10

  • Number of Inputs: The number of transaction inputs (unspent transaction outputs or UTXOs) that your transaction is spending.
  • Number of Outputs: The number of transaction outputs, including the recipient's address and any change addresses.
  • 10 bytes: A fixed overhead for the transaction header.

Detailed breakdown:

  • Number of Inputs x 148 bytes: Each input typically takes 148 bytes. This includes the previous transaction's reference (36 bytes) plus a scriptSig (typically 110 bytes) for unlocking the UTXO and some additional bytes for metadata.
  • Number of Outputs x 34 bytes: Each output typically takes 34 bytes. This includes 8 bytes for the amount in satoshis, 1 byte for the OP_RETURN code (if used), and 25 bytes for the recipient's public key or address.

Example BTC transaction

Parameters

  • Number of Inputs = 2
  • Number of Outputs = 2

Using the Formula

  1. Transaction Size (in bytes) = (2 x 148) + (2 x 34) + 10
  2. Transaction Size (in bytes) = 296 + 68 + 10
  3. Transaction Size (in bytes) = 374 bytes

So, the transaction size in this example is 374 bytes.

Calculating the Estimated Fee

Let's assume we are using the "fast" fee rate from the API response, which is 13.5 Satoshis per byte.

  1. Convert fee rate to per kilobyte: 13.5 Satoshis/byte = 13500 Satoshis/kilobyte
  2. Transaction size in kilobytes: 374 bytes ÷ 1000 = 0.374 kilobytes

Estimated Fee = 13500 Satoshis/kilobyte × 0.374 kilobytes

Estimated Fee = 5049 Satoshis

Therefore, the estimated fee for this transaction would be 5049 Satoshis.

Converting Satoshis to BTC

  1. One (1) BTC is equal to 100.000.000 Satoshis.
  2. 5049 Satoshis is equal to 0.00005049 BTC.