What is the Coinbase Transaction?

A first-principles explainer of the Bitcoin coinbase transaction: what it is, how it mints subsidy and collects fees, its structure, mining use, and validation rules.

AI Author: Cube ExplainersMar 29, 2026
Summarize this blog post with:
What is the Coinbase Transaction? hero image

Introduction

The coinbase transaction is the special first transaction in a Bitcoin block. It is how new bitcoins enter circulation (the block subsidy) and how the miner collects the transaction fees for the block. Because a coinbase is both a consensus primitive and a place miners routinely place arbitrary data, understanding its structure and rules explains miner incentives, mining practice, validation invariants, and several notable historical and security decisions in Bitcoin’s design.

What problem does the coinbase transaction solve in Bitcoin?

Bitcoin needs two things to function without a central issuer: (1) a way to reward the parties who run the block-producing work (miners) and secure the chain, and (2) a deterministic, verifiable mechanism to put newly created coins into a single owner’s control without relying on a trusted issuer. The coinbase transaction solves both by making the block’s first transaction a special, consensus-recognized claim on a precisely computed amount (the subsidy for that block era plus the collected fees).

Two invariants matter most: (A) the total supply schedule and per-block subsidy are enforced by every full node at validation time, and (B) the set of spendable outputs (the UTXO set) must behave predictably across chain reorganizations. The coinbase transaction is designed so nodes can check an included coinbase only when it appears inside a block (not as a loose mempool tx), verify that it does not claim more than the allowed subsidy plus fees, and treat new coinbase outputs differently (they are immature for a set number of blocks) to keep the UTXO invariant safe.

How is a coinbase transaction structured and what rules make it special?

TypeInput outpointCreates new coinsMempool acceptedSpend maturity
CoinbaseNull hash + 0xffffffffYes; subsidy + feesNo; block-only100 blocks
Regular transactionReferences previous outputNoYes; mempool acceptedImmediate if valid
Figure 450.1: Coinbase vs regular transactions

A coinbase transaction looks like an ordinary Bitcoin transaction at a glance (it has inputs and outputs) but several consensus exceptions and special encodings apply.

  • A block’s first transaction must be a coinbase transaction. It must have exactly one input, and that input does not reference a previous transaction output. Instead of a regular outpoint, the input uses a 32-byte zero (null) hash and the index value 0xffffffff. This serialization is how nodes immediately identify the input as a coinbase.
  • The coinbase input contains a coinbase script (the input's scriptSig bytes), which is free-form data miners may use. BIP34 requires the coinbase to start with the block height encoded in a minimally encoded push. Historically miners also put an extra-nonce or other data in this field.
  • A coinbase transaction is allowed to create more output value than its inputs; this exception is how new coins are minted: the sum of outputs in the coinbase may equal the block subsidy (determined by Bitcoin’s issuance schedule) plus the sum of transaction fees for the included transactions. Full nodes check that this claimed total does not exceed the allowed amount.
  • Coinbase transactions are valid only when included in a block; they are rejected as loose transactions in the mempool and must be validated only in block context. Moreover, outputs created by a coinbase transaction cannot be spent until they reach maturity: by default this maturity is 100 blocks (COINBASE_MATURITY = 100 in Bitcoin Core’s consensus constants).

These rules together let a node enforce supply schedule and prevent premature or fraudulent spending of newly issued coins.

What is inside the coinbase input (BIP34 height and miner-controlled data)?

The coinbase input’s scriptSig (commonly called simply the "coinbase" field) is where miners embed both consensus-required and miner-specific data.

BIP34 (Block v2, Height in Coinbase) made one item mandatory: the mined block’s height must be encoded as the first item in the coinbase scriptSig in minimally encoded form. This gives an unambiguous, parsable record of height inside the block’s first transaction and plays roles in uniqueness and post-facto block analysis.

Beyond the height, miners commonly include an extra nonce or other metadata. Practically, miners need more than the 32-bit header nonce to explore the search space: they put an extra varying value inside the coinbase (the extraNonce). Changing that extraNonce changes the coinbase transaction’s bytes, therefore the coinbase’s txid and the Merkle root, and therefore the block header hash. Pools and miners coordinate how that extraNonce is encoded so miners can continue work after the 32-bit header nonce wraps.

Two operational cautions follow from the coinbase being free-form data. First, because some byte sequences in the coinbase script could be interpreted as signature-checking opcodes, miners are advised to wrap arbitrary bytes in push opcodes to avoid accidentally increasing the block’s counted signature-operation cost. Second, there are size limits: historically implementations treat the coinbase script as limited (BIP22/BIP23 and node implementations mention a 100-byte policy), and pools/servers will reject malformed coinbase modifications (rejection reasons such as bad-cb-length or bad-cb-prefix exist in getblocktemplate implementations).

A canonical example of arbitrary coinbase data is the genesis block’s coinbase: it contains the Times headline "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"; a deliberate human message recorded immutably in Bitcoin’s first coinbase.

How do miners use the coinbase to expand hash-space via the Merkle root?

TechniqueWhere changedAffects Merkle root?Search-space effectTypical use
Header nonce80-byte block header (nonce)No2^32 candidatesInitial fast hashing
Coinbase extranonceCoinbase scriptSig / txidYesArbitrary additional entropyContinue after nonce wrap
Transaction orderingOrder of txs in blockYesSmall, costly variabilityRare; not recommended
Figure 450.2: How miners extend header search space

A block header commits to the transactions in the block via the Merkle root, which depends on the ordered list of transactions. The coinbase is always the left-most leaf of that Merkle tree. Therefore, altering the coinbase changes the Merkle root; miners exploit that to extend the header-search space.

Why is this necessary? The block header includes a 32-bit nonce. For modern hash rates that nonce overflows quickly; miners need additional degrees of freedom to continue searching for a valid header without changing which transactions are included. By changing an extraNonce inside the coinbase and recomputing the Merkle root, miners produce a new block header candidate with a different merkle_root field and resume hashing. This technique is standard across mining software and pool protocols.

Stratum v2 and other mining distribution protocols formalize how the coinbase is split and recomposed: an extended job carries a coinbase_tx_prefix and coinbase_tx_suffix, and miners insert an extranonce between them (potentially with an extranonce_prefix reserved by upstream layers). The full coinbase is then prefix + extranonce_prefix + extranonce + suffix; the coinbase txid is the double-SHA256 of that serialization (txid, not wtxid), and the Merkle path provided with the job is combined to compute the block’s Merkle root.

A worked example, conceptually:

  • The server supplies coinbase_prefix (contains BIP34 height) and coinbase_suffix (payout outputs), and a merkle path for non-coinbase txs.
  • The miner inserts its extranonce into the prefix+extranonce+suffix to make a full coinbase transaction.
  • The miner computes the coinbase txid and uses the merkle path to compute the merkle root.
  • The miner varies the header nonce until it overflows; then it increments extranonce to change the merkle root and continues searching.

This workflow is why the coinbase input must be mutable by miners or pool clients in a controlled way.

How are miner payouts assembled in the coinbase (subsidy, fees, coinbasevalue)?

A coinbase transaction’s outputs determine where the subsidy and fees land. A canonical mining flow using getblocktemplate (BIP22) produces either a coinbasetxn (a full coinbase transaction) or a coinbasevalue (a single numeric sum in satoshis). When only coinbasevalue is supplied, miners must construct the coinbase outputs themselves, ensuring the total outputs do not exceed that coinbasevalue and that the essential commitments (e.g., witness commitment when required) are present.

The block subsidy itself follows Bitcoin’s halving schedule; nodes compute the allowed subsidy for the block height and enforce it during validation. Transaction fees are computed as the sum of (input value - output value) for each included transaction and added to the amount the coinbase may claim.

getblocktemplate returns coinbaseaux to indicate data the server wishes included in the coinbase scriptSig (commonly a pool identifier or extranonce placeholder). BIP23 extends this for pooled mining, letting miners append to the coinbase scriptSig or replace the coinbase when permitted, while servers may restrict what modifications they accept.

Because coinbase formation is both protocol-critical and an interoperability point, the template protocol carefully documents which coinbase mutations are allowed and which will cause server-side rejection (for example, modifying the canonical prefix beyond appending when disallowed).

How do nodes validate coinbase transactions (maturity, limits, and consensus checks)?

Nodes accept a block only if every transaction in it is valid and consistent with consensus rules. For coinbases this means extra checks and special handling:

  • A node verifies the coinbase is the first transaction and that its input uses the null outpoint and 0xffffffff index.
  • The coinbase's total outputs must not exceed (block subsidy for that height + sum of included fees). Strict enforcement is part of block validation.
  • Coinbase outputs are immature for 100 blocks: any transaction that tries to spend a coinbase output before it has 100 confirmations is invalid under consensus.
  • Coinbase transactions must avoid creating transactions that duplicate txids of existing unspent transactions in a way that would overwrite spendable outputs. BIP30 introduced a rule preventing blocks from containing a transaction whose txid matches an earlier transaction that still has unspent outputs, to keep the set of usable outputs invariant stable under reorgs; two historic blocks were grandfathered as exceptions because they predated the rule.

The mining and validation code also treats coinbases specially in the mempool: coinbase transactions are never accepted into the mempool and transactions that spend coinbase outputs need maturity checks when reintroduced from disconnected blocks during reorganizations. Bitcoin Core’s validation and mempool code track whether mempool transactions spend coinbase outputs and remove or reject them if they would be invalid under the assumed next-block confirmation assumption.

How does SegWit use the coinbase for the witness commitment?

Segregated Witness (SegWit, BIP141) introduced a new witness commitment that is stored inside an output of the coinbase transaction. This commitment links the block header’s Merkle root with the witness data of the transactions in the block.

Mechanically, the commitment is an OP_RETURN output in the coinbase with a 36-byte push beginning with a fixed 4-byte header 0xaa21a9ed followed by a 32-byte Double-SHA256 of (witness_root | witness_reserved_value). The coinbase input’s witness must contain a single 32-byte value called the witness_reserved_value to enable this commitment. This design allowed a compact, upgradeable commitment to witness data without changing header size.

SegWit originally made this commitment optional for blocks containing no witness data. The optionality has operational implications: some historical edge-cases and near-duplicate-transaction problems could be cleaned up by making the commitment mandatory. Community discussions and follow-up analyses have considered whether mandating the commitment permanently would resolve certain obscure incidents, but that is a consensus change requiring broad coordination.

How do pools and miners coordinate coinbase construction (getblocktemplate, BIP22/BIP23, Stratum)?

ProtocolPurposeCoinbase controlShare submissionBest for
getblocktemplateProvide block templateServer may supply coinbase or coinbasevalueFull proposal or coinbase-onlySimple RPC-based mining
BIP22 / BIP23Standardize pooled mining mutationsAppend or replace allowed per serverMerkle-only or proposal formatsPool-server interoperability
Stratum / Stratum v2Distribute jobs to minersPrefix/suffix extranonce splitCompact shares / merkle submissionsHigh-performance pooled mining
Figure 450.3: Comparing GBT, BIPs 22/23, and Stratum

Mining pools and miners coordinate coinbase construction via standard RPCs and mining protocols. getblocktemplate (BIP22) is the canonical RPC that returns either a full coinbase transaction or the coinbasevalue and coinbaseaux that miners use to build payouts.

BIP23 adds pooled-mining mutations and submission abbreviations that let miners append to or otherwise mutate a server-provided coinbase safely and submit compact shares. It prescribes merkle-only submission formats and the semantics of allowed modifications so pools can permit miners to insert identifying or audit data while still enforcing server-side constraints.

Stratum (and Stratum v2) are de-facto protocols used by pools and miners to distribute jobs. They formalize how the coinbase is split into prefix/suffix and how extranonces are negotiated and injected. Stratum v2’s extended jobs and channel model explicitly support miner-supplied transaction selection and extranonce partitioning (extranonce_prefix and locally reserved bytes), improving decentralization and splitting of search space.

Security research has shown real-world risks around mining protocols and coinbase handling. Passive monitoring of Stratum traffic (and even packet timings) can leak miner earnings or identify miners; active attacks can hijack shares. Proposed mitigations, such as Bedrock, introduce per-miner secrets (a "mining cookie") to prevent attackers reconstructing or hijacking puzzles.

What historical incidents and risks shaped coinbase rules?

Several historical and operational issues motivate the special-case rules around coinbase transactions:

  • Duplicate transaction / overwriting problem (BIP30): Coinbase transactions are easy to duplicate. If a later block contains a transaction with the same identifier as an earlier transaction that still has unspent outputs, a reorg could change which outputs exist. BIP30 forbids constructing blocks that would introduce such duplicates unless the earlier instance had no spendable outputs; two early exceptions had to be grandfathered.
  • BIP34 (height-in-coinbase) was adopted to add a simple canonical unique value in the coinbase and aid upgrades.
  • SegWit and witness commitment: the optional coinbase witness commitment was designed to commit witness data without changing the header; debates persist about whether that commitment should be mandatory to close certain obscure edge cases.
  • Miner metadata leakage: because miners embed identifiers in the coinbase (for pool accounting or identification), an observer can link blocks/shares to miners or infer revenue. Research on Stratum demonstrated both privacy leakage and active hijacking risks.
  • Accidental sigop consumption: arbitrary coinbase bytes can be misinterpreted as signature-checking opcodes and count toward the block’s sigop limit; miners are advised to place arbitrary data using push opcodes to avoid this.
  • Operational compatibility: mining software and pool servers must agree on extranonce sizing, coinbase encoding, and what mutations are allowed. Recent changes in bitcoin/bitcoin reduced the default exposure of a dummy extraNonce on certain internal interfaces to avoid forcing external software to strip or ignore bitcoin-core-generated data, showing how these choices propagate through the ecosystem.

When does the coinbase design fail or depend on protocol assumptions?

The coinbase transaction’s design depends on several assumptions and conventions that could change with consensus decisions:

  • The exact block subsidy schedule is a protocol parameter (the halving schedule), and changes would change how nodes compute allowable coinbase outputs.
  • The coinbase script's freedom to include arbitrary data is mostly convention and constrained by size and sigop semantics; a future consensus change could restrict or forbid arbitrary data in the coinbase.
  • The witness commitment’s optionality or mandatory status is a policy point. Making it mandatory would change how coinbase transactions must be constructed and how miners/pools must behave. Conversely, leaving it optional preserves some backward-compatibility flexibility but retains certain edge-case risks.
  • Pool and mining protocols assume the coinbase will be mutable in well-defined ways to permit extranonce insertion; any protocol that prevented miners from changing the coinbase would severely limit mining search-space options and centralize block construction.

Coinbase handling checklist for miners, pool operators, and developers

When building or operating coinbase-related software, the organizing principle is: preserve consensus invariants while giving miners the ability to vary the coinbase safely. Concretely:

  • Always include the BIP34 height as the first item in coinbase scriptSig for blocks where that is required.
  • Respect coinbase max input (coinbasevalue) supplied by getblocktemplate and check your constructed coinbase does not claim more than allowed.
  • Place arbitrary bytes using push opcodes to avoid accidental sigops.
  • If implementing extranonce mechanics, partition extranonce space explicitly (extranonce_prefix vs local bytes) and ensure agreed sizes with upstream/downstream.
  • Include the SegWit witness commitment output in the coinbase when witness data exists and follow BIP141 format rules for the OP_RETURN commitment and witness_reserved_value.
  • Remember coinbase outputs are immature for COINBASE_MATURITY (100) blocks and ensure wallet/accounting systems do not assume immediacy.
  • Be aware of privacy leaks from coinbase-identifying data and use care when embedding persistent identifiers.

Conclusion; the compression point

The coinbase transaction is Bitcoin’s minting primitive and miners’ payout mechanism, implemented as a protocol-exempt special transaction that is only valid inside a block. Its design balances two needs: enforceable monetary issuance and practical miner ergonomics (extra nonce space, witness commitment, pool accounting). That balance produces special rules; unique serialization, a mandatory height prefix (BIP34), maturity before spendability, witness commitments (BIP141), and carefully prescribed mining-protocol interactions (BIP22/BIP23, Stratum). Understanding the coinbase is understanding how Bitcoin anchors economic incentives into consensus-level data structures while protecting the invariant that the set of spendable outputs remains predictable across reorganizations.

If you build or operate mining software, pool code, or block-construction tooling, treat coinbase handling as a consensus-critical surface: follow BIPs, respect getblocktemplate guidance, and avoid ad-hoc coinbase mutations that could cause rejections, privacy leaks, or validation failures.

Frequently Asked Questions

Why are coinbase transactions only valid inside blocks and not allowed in the mempool?

Because coinbase transactions create new coins and rely on block context (subsidy + fees and block height), nodes only accept them when they appear inside a block; loose coinbase transactions are rejected from the mempool and are validated only during block validation.

What prevents a miner from minting more bitcoins than the protocol allows in the coinbase?

Full nodes enforce that a coinbase's total outputs do not exceed the block subsidy for that height plus the sum of included transaction fees, and they perform this check during block validation to prevent miners from minting more than the allowed amount.

How long must coinbase outputs wait before they can be spent and why?

Outputs created by a coinbase are immature for 100 blocks (COINBASE_MATURITY = 100 in Bitcoin Core), so any attempt to spend them before they have 100 confirmations is invalid under consensus.

What is the extraNonce in the coinbase and why do miners use it?

Miners put an extraNonce into the coinbase scriptSig so changing that field modifies the coinbase txid and therefore the Merkle root, giving miners additional degrees of freedom beyond the 32-bit header nonce to continue searching for a valid block hash.

What does BIP34 change about the coinbase and why is the block height included there?

BIP34 requires that the block height be encoded as the first item in the coinbase scriptSig in minimally encoded form; this gives an unambiguous record of height in the coinbase and aids uniqueness and upgrade parsing.

How does Segregated Witness (SegWit) use the coinbase transaction to commit to witness data?

SegWit uses a witness commitment stored in a coinbase OP_RETURN output (a 36-byte push with a 4-byte header 0xaa21a9ed plus a 32-byte double-SHA256) and requires the coinbase input witness to include a 32-byte witness_reserved_value so the header can commit to witness data.

Are there privacy or security risks from putting arbitrary data (like pool IDs) in the coinbase?

Embedding identifiers or accounting metadata in the coinbase lets observers link blocks and shares to mining entities, and research on Stratum shows that mining-protocol traffic and coinbase handling can leak earnings or be hijacked - mitigations like per-miner secrets (e.g., Bedrock) have been proposed.

What is the duplicate-transaction (BIP30) problem and how does it affect coinbase handling?

BIP30 was adopted to forbid creating a transaction in a block that has the same txid as an earlier transaction that still has unspent outputs, because such duplicates could change which outputs exist after a reorg; two historic blocks were grandfathered as exceptions.

How do mining pools and miners coordinate who can change the coinbase and where extranonces go?

Pools and miners coordinate coinbase construction using getblocktemplate (BIP22), pooled-mining extensions (BIP23), and de-facto protocols like Stratum/Stratum v2, which formalize coinbase prefix/suffix and extranonce insertion rules so miners can safely mutate the coinbase for search-space and payout purposes.

Could future consensus changes restrict what arbitrary data miners are allowed to put in the coinbase?

Yes - the coinbase scriptSig is conventionally free-form but constrained by size, sigop semantics, and BIP rules, and the article notes that future consensus changes could further restrict or forbid arbitrary coinbase data (for example, making the witness commitment mandatory would change coinbase construction).

Related reading

Keep exploring

Your Trades, Your Crypto