How a Bitcoin Transaction Works?
Introduction
Have you ever wondered what happens behind the scenes when you send Bitcoin to someone? How does the network know you have enough Bitcoin? How does it verify the transaction is valid? How do miners decide which transactions to include in a block?
This guide will explain how Bitcoin transactions work in a technical but still accessible way. You'll understand concepts like inputs, outputs, UTXOs, digital signatures, and fees. Our goal is to teach you to understand transactions in practice, not just in theory.
We'll use real examples with fictional values to illustrate each concept. By the end of this guide, you'll be able to read a Bitcoin transaction on a blockchain explorer and understand exactly what's happening.
Fundamental Concepts
What is a Bitcoin Transaction?
A Bitcoin transaction is a value transfer on the blockchain that moves Bitcoins from one or more source addresses to one or more destination addresses.
Unlike traditional banking systems, Bitcoin doesn't use "accounts" with balances. Instead, it uses a system of unspent coins (UTXOs) that are transferred from one person to another.
Main characteristics:
- Transactions are atomic (either complete fully or fail completely)
- Cannot be modified after confirmation
- Are public and verifiable by anyone
- Are irreversible (once confirmed)
UTXO: Unspent Transaction Outputs
UTXO (Unspent Transaction Output) are "coins" of Bitcoin that were received in a previous transaction but haven't been spent yet.
Think of UTXOs as physical cash bills:
- When someone pays you, you receive one or more "bills" (UTXOs)
- Each bill has a specific value
- To pay someone, you need to "give" one or more bills
- You may need to give a large bill and receive change
Practical example:
- John has 0.5 BTC (received in a previous transaction)
- Mary has 0.3 BTC (received in another transaction)
- Peter has 1.2 BTC (received in another transaction)
Each of these values is a different UTXO. When Peter wants to send 0.8 BTC to Ann, he needs to use his 1.2 BTC UTXO and create two outputs: 0.8 BTC for Ann and 0.4 BTC change for himself.
Inputs and Outputs
Inputs are references to previous UTXOs being "spent" in the transaction. Outputs are new UTXOs being created in the transaction.
Basic structure:
Bitcoin Transaction
├── Inputs (entries - UTXOs being spent)
│ ├── Input 1: reference to previous transaction + value
│ └── Input 2: reference to previous transaction + value
├── Outputs (exits - new UTXOs being created)
│ ├── Output 1: destination address + value
│ └── Output 2: change address + value
└── Fee: difference between inputs and outputs
Anatomy of a Bitcoin Transaction
Transaction Components
1. Version:
- Protocol version number
- Indicates which rules the transaction follows
2. Inputs:
- List of UTXOs being spent
- Each input references a previous transaction
- Includes unlocking script (signature)
3. Outputs:
- List of new UTXOs being created
- Each output specifies address and value
- Includes locking script (conditions to spend)
4. Locktime:
- Timestamp or block number
- Transaction is only valid after this time/block
- Usually is 0 (valid immediately)
Practical Example: Simple Transaction
Let's follow a transaction from start to finish with fictional values:
Initial situation:
- Ann has 0.5 BTC received in transaction ABC123 (UTXO)
- Ann wants to send 0.3 BTC to Carlos
- Network fee: 0.0001 BTC
Transaction created:
Transaction XYZ789
├── Input
│ └── Input 1:
│ ├── Reference: ABC123, output 0 (0.5 BTC)
│ └── Signature: [Ann's signature]
├── Outputs
│ ├── Output 0: Carlos's Address (0.3 BTC)
│ └── Output 1: Ann's Address (0.1999 BTC - change)
└── Fee: 0.0001 BTC (0.5 - 0.3 - 0.1999)
What happens:
- Ann uses her 0.5 BTC UTXO (input)
- Creates output of 0.3 BTC for Carlos
- Creates output of 0.1999 BTC change for herself
- Fee of 0.1 mBTC (0.0001 BTC) is paid to miners
- Total: 0.5 BTC (input) = 0.3 BTC + 0.1999 BTC + 0.0001 BTC (outputs + fee)
After confirmation:
- Ann's 0.5 BTC UTXO is marked as "spent"
- New UTXO of 0.3 BTC is created for Carlos (can be spent)
- New UTXO of 0.1999 BTC is created for Ann as change
Inputs
What Are Inputs?
Inputs are references to outputs from previous transactions being spent in the current transaction.
Each input contains:
- Hash of previous transaction: Identifies which transaction contains the UTXO
- Output index: Which output from that transaction is being used
- Unlocking script: Signature and public key that prove ownership
Input Structure
Input {
previous_output: {
hash: "abc123...", // Hash of previous transaction
index: 0 // Which output to use (0 = first)
},
script_sig: "[signature]", // Unlocking script
sequence: 0xffffffff // Used for replace-by-fee
}
Multiple Input Example
Situation:
- Mary wants to send 0.8 BTC to John
- Mary has two UTXOs:
- UTXO 1: 0.5 BTC from transaction DEF456
- UTXO 2: 0.4 BTC from transaction GHI789
Transaction created:
Transaction JKL012
├── Inputs
│ ├── Input 1:
│ │ ├── Reference: DEF456, output 0 (0.5 BTC)
│ │ └── Signature: [Mary's signature]
│ └── Input 2:
│ ├── Reference: GHI789, output 0 (0.4 BTC)
│ └── Signature: [Mary's signature]
├── Outputs
│ ├── Output 0: John's Address (0.8 BTC)
│ └── Output 1: Mary's Address (0.0999 BTC - change)
└── Fee: 0.0001 BTC
Total inputs: 0.5 + 0.4 = 0.9 BTC Total outputs: 0.8 + 0.0999 = 0.8999 BTC Fee: 0.9 - 0.8999 = 0.0001 BTC
Unlocking Script (ScriptSig)
ScriptSig is the script that "unlocks" the UTXO, proving you have the right to spend it.
Most common types:
1. Pay-to-PubKeyHash (P2PKH):
- Traditional format
- Requires signature and public key
- Script:
<signature> <public key>
2. Pay-to-ScriptHash (P2SH):
- For addresses starting with "3"
- Allows more complex scripts
- Requires redeem script and data
3. Pay-to-Witness-PubKeyHash (P2WPKH):
- For SegWit addresses (bc1...)
- Signature is separated (witness data)
- Lower fee cost
Outputs
What Are Outputs?
Outputs are new UTXOs being created in the transaction. They specify where Bitcoin should go and in what amount.
Each output contains:
- Value: Amount of Bitcoin (in satoshis)
- Locking script: Conditions that must be met to spend this output
Output Structure
Output {
value: 30000000, // 0.3 BTC in satoshis
script_pubkey: "[script]" // Locking script
}
Types of Outputs
1. Pay-to-PubKeyHash (P2PKH):
- Addresses starting with "1"
- Script:
OP_DUP OP_HASH160 <public key hash> OP_EQUALVERIFY OP_CHECKSIG
2. Pay-to-ScriptHash (P2SH):
- Addresses starting with "3"
- Script:
OP_HASH160 <script hash> OP_EQUAL
3. Pay-to-Witness-PubKeyHash (P2WPKH):
- SegWit addresses starting with "bc1"
- Script:
OP_0 <public key hash> - More efficient (lower fees)
Example: Transaction with Multiple Outputs
Situation:
- Peter wants to send Bitcoin to 3 people:
- 0.2 BTC to Alice
- 0.15 BTC to Bob
- 0.1 BTC to Charlie
- Peter has 0.5 BTC in one UTXO
Transaction created:
Transaction MNO345
├── Input
│ └── Input 1: Peter's 0.5 BTC UTXO
├── Outputs
│ ├── Output 0: Alice's Address (0.2 BTC)
│ ├── Output 1: Bob's Address (0.15 BTC)
│ ├── Output 2: Charlie's Address (0.1 BTC)
│ └── Output 3: Peter's Address (0.0499 BTC - change)
└── Fee: 0.0001 BTC
Validation:
- Input: 0.5 BTC
- Outputs: 0.2 + 0.15 + 0.1 + 0.0499 = 0.4999 BTC
- Fee: 0.0001 BTC
- Total: 0.5 BTC ✓
UTXO: Unspent Transaction Output System
How UTXOs Work
UTXO system is different from account system:
Account System (Banks):
- You have an account with balance: 1.0 BTC
- To send 0.3 BTC, balance decreases to 0.7 BTC
- Simple and intuitive
UTXO System (Bitcoin):
- You have separate UTXOs: [0.5 BTC, 0.3 BTC, 0.2 BTC]
- To send 0.3 BTC, you use one UTXO or combine several
- More complex, but more flexible
Example: UTXO Tracking
Transaction history:
Transaction 1 (block 100):
- Alice receives 1.0 BTC from a previous transaction
- Creates UTXO: Alice has 1.0 BTC (UTXO A)
Transaction 2 (block 150):
- Alice sends 0.4 BTC to Bob
- Uses UTXO A (1.0 BTC) as input
- Creates outputs:
- Bob receives 0.4 BTC (UTXO B)
- Alice receives 0.5999 BTC change (UTXO C)
- UTXO A is marked as spent
Transaction 3 (block 200):
- Alice sends 0.2 BTC to Carlos
- Uses UTXO C (0.5999 BTC) as input
- Creates outputs:
- Carlos receives 0.2 BTC (UTXO D)
- Alice receives 0.3998 BTC change (UTXO E)
- UTXO C is marked as spent
Current state:
- Unspent UTXOs:
- UTXO B: Bob has 0.4 BTC
- UTXO D: Carlos has 0.2 BTC
- UTXO E: Alice has 0.3998 BTC
UTXOs and Privacy
Each UTXO can be tracked:
- Blockchain is public
- UTXOs can be connected
- Cluster analysis can identify relationships
Best practices for privacy:
- Use new addresses for each receipt
- Don't reuse addresses
- Consider using CoinJoin to mix UTXOs
- Separate UTXOs from different sources
Digital Signatures
How Signatures Work
Digital signature proves you have the private key controlling the UTXO, without revealing the private key.
Process:
- You create transaction
- Transaction hash is created
- You sign hash with your private key
- Signature is included in input
- Network verifies signature using public key
ECDSA: Signature Algorithm
Bitcoin uses ECDSA (Elliptic Curve Digital Signature Algorithm):
- Elliptic curve: secp256k1
- Generates key pair (private and public)
- Signature is a pair of numbers (r, s)
Characteristics:
- Signature is deterministic (same key + same message = same signature)
- But Bitcoin uses random nonce for security
- Signature is unique and cannot be forged
Signing Process
Step by step:
-
Create transaction:
- Define inputs and outputs
- Calculate fees
- Create transaction structure
-
Create hash to sign:
- Transaction hash (minus unlocking scripts)
- Includes inputs, outputs, locktime
-
Sign with private key:
- Use ECDSA to sign hash
- Generate pair (r, s)
-
Include signature in input:
- Add unlocking script
- Include signature and public key
-
Broadcast to network:
- Send transaction to Bitcoin nodes
- Nodes verify and propagate
Signature Verification
Network verifies if signature is valid:
- Extracts signature from input
- Extracts public key from input
- Recreates hash that was signed
- Verifies if signature matches hash and public key
- If valid, transaction can proceed
If signature is invalid:
- Transaction is rejected
- Never enters mempool
- Won't be included in block
Example: Signature in Practice
Transaction to be signed:
- Ann wants to send 0.5 BTC to Carlos
- Uses UTXO of 1.0 BTC
Process:
- Ann's wallet creates transaction structure
- Transaction hash is calculated:
hash123... - Wallet signs
hash123...with Ann's private key - Signature generated:
(r=abc..., s=def...) - Input includes:
- Reference to UTXO
- ScriptSig with signature and Ann's public key
Verification:
- Bitcoin nodes extract signature and public key
- Recreate transaction hash
- Verify if signature is valid
- If valid, transaction is accepted
Transaction Fees
How Fees Work
Transaction fee is the difference between total value of inputs and total value of outputs.
Fee = Sum of all inputs - Sum of all outputs
Why it exists:
- Incentivizes miners to include transaction in block
- Prevents spam on network
- Prioritizes important transactions
Fee Calculation
Fee is not explicitly defined:
- You don't say "I want to pay 0.0001 BTC fee"
- Instead, you define output values
- Fee is what "remains"
Example:
- Input: 1.0 BTC
- Output to recipient: 0.999 BTC
- Implicit fee: 1.0 - 0.999 = 0.001 BTC (1 mBTC)
Fee by Size (sat/vB)
Fee is based on transaction size in bytes, not transferred value.
Factors affecting size:
- Number of inputs (more inputs = larger transaction)
- Number of outputs (more outputs = larger transaction)
- Script type (SegWit = smaller)
- Signature length
Fee expressed in:
- sat/vB (satoshis per virtual byte)
- Higher sat/vB = faster confirmation
Example: Fee Calculation
Simple transaction:
- 1 input (traditional P2PKH)
- 2 outputs (recipient + change)
- Size: ~250 bytes
- Chosen fee: 10 sat/vB
Calculation:
- Total fee: 250 bytes × 10 sat/vB = 2,500 satoshis
- Fee in BTC: 0.000025 BTC
Complex transaction:
- 5 inputs (traditional P2PKH)
- 3 outputs
- Size: ~1,250 bytes
- Chosen fee: 15 sat/vB
Calculation:
- Total fee: 1,250 bytes × 15 sat/vB = 18,750 satoshis
- Fee in BTC: 0.0001875 BTC
Observe: Same fee per byte, but larger transaction pays more total.
Fee Optimization
How to reduce fees:
1. Use SegWit:
- Addresses starting with "bc1"
- Signatures separated (witness data)
- Smaller transactions = lower fees
- Can save 30-40%
2. Combine UTXOs:
- Fewer inputs generally = smaller transaction
- But be careful: many small UTXOs can be expensive to spend
- Balance number of UTXOs
3. Avoid very small outputs:
- Small outputs increase transaction size
- Consider sending larger amounts at once
4. Choose low traffic times:
- Weekends may have lower fees
- Peak hours have higher fees
Mempool and Fees
Mempool is the "queue" of transactions waiting for confirmation:
How it works:
- Transactions are sent to mempool
- Miners choose which to include in next block
- Usually prioritize transactions with higher fee (sat/vB)
- Transactions with very low fee may wait long time
Strategies:
- High fee: Confirms in ~10 minutes
- Medium fee: Confirms in 1-3 hours
- Low fee: May wait hours or days
During congestion:
- Many transactions competing
- Fees increase
- Low fee transactions may get "stuck"
Complete Example: Tracking a Transaction
Let's follow a complete transaction from start to finish:
Initial Situation
UTXO state:
- Robert has:
- UTXO 1: 0.8 BTC (from transaction ABC123)
- UTXO 2: 0.5 BTC (from transaction DEF456)
- Robert's total: 1.3 BTC
Transaction to Be Created
Objective: Robert wants to send 1.0 BTC to Juliana
Challenge: No individual UTXO has 1.0 BTC, so needs to combine
Transaction Creation
Robert's wallet creates transaction:
Transaction GHI789
├── Version: 2
├── Inputs
│ ├── Input 0:
│ │ ├── previous_output: {
│ │ │ hash: "abc123...",
│ │ │ index: 0
│ │ │ },
│ │ └── script_sig: "[Robert's signature for UTXO 1]"
│ └── Input 1:
│ ├── previous_output: {
│ │ hash: "def456...",
│ │ index: 0
│ │ },
│ └── script_sig: "[Robert's signature for UTXO 2]"
├── Outputs
│ ├── Output 0:
│ │ ├── value: 100000000 (1.0 BTC in satoshis)
│ │ └── script_pubkey: "[Juliana's address]"
│ └── Output 1:
│ ├── value: 29999000 (0.29999 BTC in satoshis - change)
│ └── script_pubkey: "[Robert's address]"
├── Locktime: 0
└── Implicit fee: 0.00001 BTC (1.3 - 1.0 - 0.29999)
Transaction Validation
Bitcoin nodes verify:
-
Verify inputs:
- UTXO 1 exists? ✓
- UTXO 2 exists? ✓
- Already spent? ✗ (no, they're available)
-
Verify signatures:
- Input 0 signature valid? ✓
- Input 1 signature valid? ✓
- Robert controls both UTXOs? ✓
-
Verify values:
- Total inputs: 0.8 + 0.5 = 1.3 BTC ✓
- Total outputs: 1.0 + 0.29999 = 1.29999 BTC ✓
- Fee: 1.3 - 1.29999 = 0.00001 BTC ✓
- Fee > 0? ✓
-
Verify scripts:
- Locking scripts valid? ✓
- Unlocking scripts correct? ✓
Result: Transaction valid! ✓
Broadcast and Mempool
Transaction is sent to network:
- Robert sends transaction GHI789 to nearby nodes
- Nodes verify (as above)
- If valid, propagate to other nodes
- Transaction enters mempool
- Miners see transaction
In mempool:
- Fee: 0.00001 BTC
- Size: ~500 bytes
- Fee per byte: ~20 sat/vB
- Priority: Medium-High (depending on congestion)
Mining and Confirmation
Miner chooses to include transaction:
- Miner sees transaction in mempool
- Fee is acceptable (20 sat/vB)
- Includes in block being mined
Block is mined:
- Block #800,000 contains transaction GHI789
- Block is added to blockchain
- Transaction receives first confirmation
State After Confirmation
Old UTXOs:
- UTXO 1 (0.8 BTC) from Robert: ❌ SPENT
- UTXO 2 (0.5 BTC) from Robert: ❌ SPENT
New UTXOs created:
- UTXO 3 (1.0 BTC) for Juliana: ✅ AVAILABLE
- UTXO 4 (0.29999 BTC) for Robert (change): ✅ AVAILABLE
Updated balance:
- Robert: 0.29999 BTC (change)
- Juliana: 1.0 BTC (received)
Reading Transactions on Blockchain Explorer
What to Look For
When viewing a transaction on explorer:
1. Transaction ID/Hash:
- Unique identifier
- Example:
abc123def456...
2. Inputs:
- How many UTXOs are being spent
- Value of each input
- Source addresses
3. Outputs:
- How many new UTXOs are being created
- Value of each output
- Destination addresses
4. Fee:
- Total paid in fee
- Fee per byte (if shown)
5. Confirmations:
- How many blocks since transaction
- More confirmations = more secure
Example: Interpreting a Transaction
Transaction on explorer:
Transaction: 7a8b9c1d2e3f...
Status: Confirmed (6 confirmations)
Inputs:
├── 0.5 BTC from 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
└── 0.3 BTC from 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
Outputs:
├── 0.7 BTC to 1C4hvzGJdqkUqXx...
└── 0.099 BTC to 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
Fee: 0.001 BTC
Size: 374 bytes
Interpretation:
- Someone combined two UTXOs (0.5 + 0.3 = 0.8 BTC)
- Sent 0.7 BTC to someone
- Received 0.099 BTC change (same address as first input)
- Paid 0.001 BTC fee
- Transaction is confirmed (secure)
Frequently Asked Questions
Why does Bitcoin use UTXO instead of accounts?
UTXO allows:
- Better privacy (each transaction can use new addresses)
- Greater parallelism (multiple transactions can be processed simultaneously)
- Simpler verification (don't need to check entire history)
- Better origin tracking
What happens if I send more than I have?
Transaction will be rejected. Nodes verify that:
- Sum of inputs ≥ sum of outputs
- All UTXOs exist and haven't been spent
- You have permission to spend (valid signature)
Can I cancel a transaction?
No, after sent and confirmed, it cannot be canceled. Before confirmation, you can try:
- Replace-by-Fee (RBF): Send new transaction with higher fee
- Child Pays for Parent (CPFP): Create child transaction that pays higher fee
Why do fees vary so much?
Fees depend on:
- Network congestion (many transactions = higher fees)
- Your transaction size (more inputs/outputs = larger)
- Urgency (higher fee = faster confirmation)
What is dust?
Dust are very small outputs (usually < 546 satoshis) that aren't worth spending because fee would be higher than value. Many wallets don't create dust outputs.
Conclusion
Now you understand how Bitcoin transactions work in practice. The main concepts are:
- UTXOs are "unspent coins" - different system from bank accounts
- Inputs spend previous UTXOs - reference past transactions
- Outputs create new UTXOs - specify destination and value
- Signatures prove ownership - without revealing private key
- Fees are the difference - between inputs and outputs, based on size
Understanding Bitcoin transactions gives you power to:
- Verify transactions manually
- Optimize fees
- Understand why some transactions are more expensive
- Improve privacy
- Debug problems
Continue exploring transactions on blockchain explorer. The more you practice, the more intuitive it becomes. The UTXO system may seem complex initially, but it's an elegant solution that enables a truly decentralized financial system.