Network models3 min read

Calculating Bitcoin Transaction Fees from Inputs and Outputs

Calculate Bitcoin fees from resolved input values and outputs, preserve exact satoshi arithmetic, and distinguish total fee from fee rate.

Editorial illustration accompanying calculating bitcoin transaction fees from inputs and outputs.

Overview

When translating these concepts into an integration, keep the scope described by the wallet history api with the result. The examples in wallet transaction history and smart contract event logs show how the same distinction affects neighbouring data questions.

For an ordinary Bitcoin transaction, the fee is the difference between total input value and total output value. Input values must be resolved from the previous outputs being spent.

Resolve values before summing

Inputs reference outpoints; they do not simply carry a trustworthy standalone amount field in the transaction structure. Fetch or retain the referenced outputs. Use integer satoshi quantities and exclude special cases such as coinbase transactions from an ordinary input-minus-output calculation. Missing previous-output evidence should produce an unresolved fee, not a guessed value.

Worked example: exact fee

Resolved inputs total 100000 satoshis. Outputs total 98500. The transaction fee is 1500 satoshis. If its virtual size is 150 virtual bytes under the selected size calculation, the fee rate is ten satoshis per virtual byte. Total fee and fee rate are different units.

Allocate wallet costs deliberately

A collaborative transaction can involve multiple participants. The transaction fee does not automatically establish how much one wallet economically paid. Test several inputs from different ownership groups and missing input history. Preserve the original transaction-level fee and keep any wallet allocation as a separate, documented interpretation.

A practical acceptance test

Resolve input values totalling 100000 satoshis and outputs totalling 98500, giving fee 1500. With virtual size 150, assert fee rate ten satoshis per virtual byte in a separate field. Remove one previous-output value and require an unresolved calculation rather than a negative fee or guessed input amount.

Questions about the topic

Frequently asked questions

Can fees be calculated without input values?

Not reliably; referenced output values are required.

Is satoshis per virtual byte a total fee?

No. It is a fee rate.

Standards & technical documentation

Further reading

{{TODO: author name}}

Practical explanations of blockchain data, software integration and the context behind a record.

About Indexbase
← Back to all articles

Build with better context.

Get an update when private beta opens.

Form setup in progress. Nothing entered here is sent or saved. {{TODO: endpoint}} See the full form and email alternative.