BR Academy
0%
How Bitcoin Works u2014 Architecture·Lesson 7 of 37·8 min

Transactions and the Mempool

The Concept

Once a node validates your transaction (from "nodes-and-peers"), it doesn't go straight into a block. It waits in the mempool — short for "memory pool" — a holding area of unconfirmed, validated transactions that every full node maintains independently. There is no single, global mempool; each node's mempool is its own local view, built from whatever valid transactions it has seen so far, which is why two nodes can briefly disagree about which transactions are currently pending, even though they agree completely about which transactions are already confirmed on the chain. Miners assemble candidate blocks by pulling transactions out of their own mempool, and because each block has a limited amount of space, miners generally prioritize whichever waiting transactions offer the highest fee per unit of data, since the fee is revenue they collect directly.

A Bitcoin transaction's anatomy has three parts. Inputs reference specific previous outputs being spent — effectively, "here is proof I'm entitled to spend this specific amount that was sent to me earlier." Outputs specify the destination addresses and amounts receiving coins. The fee is simply whatever is left over: total inputs minus total outputs, and that difference goes to whichever miner includes the transaction in a block. There's no separate "fee" field to fill in — it falls out of the arithmetic, which is why getting the inputs and outputs right matters. This model is often called UTXO — unspent transaction output — because every input must reference a whole, previously-unspent output in full; you cannot spend half of one. Any leftover amount beyond what you intend to pay must be sent back to yourself as a separate "change" output, exactly the way a cashier gives change when you hand over a bill larger than the price of your purchase.

transaction = {
  inputs:  [{ from_output: "tx_abc:0", amount: 0.03 },
            { from_output: "tx_def:1", amount: 0.02 }],
  outputs: [{ to: "bc1q...recipient", amount: 0.0498 },
            { to: "bc1q...change_address", amount: 0.0000 }],  // change is one of the outputs
  fee: sum(inputs) - sum(outputs)
}

A transaction can have any number of inputs and outputs, not just one of each. A wallet with many small previously-received amounts may need to combine several inputs to cover one payment, and a single transaction can pay several recipients at once by including multiple outputs — a company running payroll in BTC, for instance, could pay every employee in one transaction with one output per employee, saving on total fees compared to sending each payment separately.

Worked Example

Here is a real-style transaction with two inputs and two outputs. Alice is paying Bob, but her wallet only has two previously received amounts available to spend: 0.03 BTC and 0.02 BTC, for a total of 0.05 BTC in inputs. She owes Bob exactly 0.03 BTC. Her wallet creates two outputs: one sending 0.03 BTC to Bob's address, and a second "change" output sending whatever remains back to an address Alice controls — this is necessary because Bitcoin inputs must be spent in full; you can't partially spend a 0.05 BTC input and leave 0.02 BTC of it untouched the way you might hand over part of a bill.

Suppose Alice's wallet sets the change output to 0.0198 BTC. Total outputs are 0.03 + 0.0198 = 0.0498 BTC. Total inputs are 0.05 BTC. The fee is 0.05 − 0.0498 = 0.0002 BTC, which goes to whichever miner mines this transaction into a block. If the mempool is quiet, 0.0002 BTC might be more than enough for next-block confirmation. If the mempool is full of competing transactions offering a higher fee per byte, this transaction will sit, unconfirmed, until either the mempool clears or Alice's wallet lets her rebroadcast with a higher fee (a decision covered in detail in "fees-and-transaction-cost").

Now suppose a second scenario: Alice's wallet instead holds five small previously received amounts of 0.01 BTC each (0.05 BTC total) rather than two larger ones. To pay Bob the same 0.03 BTC, her wallet would need to combine three of those five inputs (0.03 BTC exactly, with no change needed) or four of them (0.04 BTC, generating a 0.01 BTC change output after the fee). Combining more, smaller inputs produces a larger transaction in bytes than combining fewer, larger inputs of the same total value, which — since fees are charged per byte, not per BTC moved — means a wallet holding many small amounts typically pays a higher fee to spend the same total value than one holding fewer, larger amounts.

Exercise

Given a transaction with inputs totaling 0.05 BTC and outputs totaling 0.0498 BTC, calculate the fee in BTC (show your work: inputs minus outputs). Then, in two to three sentences, explain why a transaction offering a very low fee per byte might sit unconfirmed in the mempool for hours during a busy period — referencing the fact that miners choose which waiting transactions to include and are not obligated to include any specific one. Finally, explain in one sentence why a wallet holding many small previously-received amounts tends to pay higher fees than one holding fewer, larger amounts, to spend the same total value.

Recap

  • A transaction has inputs (previously received amounts being spent in full, per the UTXO model), outputs (destination addresses and amounts, often including a change output), and a fee that is simply inputs minus outputs.
  • Validated transactions wait in each node's own local mempool until a miner selects them for a block, generally prioritizing the highest fee per byte.
  • A low-fee transaction isn't invalid — it's just less attractive to miners, so it can sit unconfirmed indefinitely during busy periods; and spending many small inputs costs more in fees, byte for byte, than spending fewer large ones, which is the practical reason fee selection and wallet management both matter.

Resources

  • Bitcoin Developer Guide, "Transactions" (developer.bitcoin.org/devguide/transactions.html) — inputs, outputs, and the UTXO model in full detail.
  • mempool.space — view live, unconfirmed transactions waiting in the mempool.
  • Bitcoin Optech, "Transaction fees" primer (bitcoinops.org) — background on fee markets.