Skip to content

feat: add difficulty adjustment tool and info about it #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions decoding/difficulty-adjusment.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: 'Bitcoin Difficulty Adjustment'
description: 'Understanding how Bitcoin automatically adjusts mining difficulty to maintain consistent block times'
date: '2024-03-19'
author: 'DecodingBitcoin'
layout: TopicBanner
icon: 'FaTools'
category: 'Tools'
---

Bitcoin's difficulty adjustment mechanism is one of its most important features, ensuring that blocks are mined at a relatively consistent rate regardless of how much mining power (hashrate) is on the network.

## How Does Difficulty Adjustment Work?

Every 2,016 blocks (approximately 2 weeks), Bitcoin automatically adjusts its mining difficulty based on how quickly blocks were mined in the previous period:

- If blocks were mined too quickly (less than 10 minutes on average), difficulty increases
- If blocks were mined too slowly (more than 10 minutes on average), difficulty decreases
- The maximum adjustment is limited to 4x increase or 1/4x decrease

This self-correcting mechanism helps maintain Bitcoin's predictable issuance schedule and ensures network security remains proportional to mining investment.

## Live Difficulty Estimator

This tool monitors the current mining difficulty and estimates the next adjustment:

<DifficultyEstimator />

## Why is Difficulty Adjustment Important?

1. **Predictable Issuance**: Keeps block times around 10 minutes, maintaining Bitcoin's planned supply schedule
2. **Network Security**: Adjusts difficulty to match total network hashpower
3. **Mining Economics**: Helps balance mining profitability as hardware efficiency improves
4. **Decentralization**: Allows Bitcoin to adapt to changing network conditions without central coordination

## Technical Details

The difficulty adjustment formula is:

```
new_difficulty = current_difficulty * (actual_timespan / target_timespan)
```


Where:
- `target_timespan` = 2,016 blocks * 10 minutes = 20,160 minutes (2 weeks)
- `actual_timespan` = time taken for last 2,016 blocks (measured in seconds)
- `actual_timespan` is constrained between 1/4 and 4 times the target to limit volatility

### Key Components

1. **Target (nBits)**
- A 256-bit number that a block hash must be below
- Inversely proportional to difficulty
- Stored in compact format in block headers

2. **Block Time**
- Target average: 10 minutes
- Natural variance due to mining's probabilistic nature
- Measured over 2,016 block periods

3. **Adjustment Period**
- Every 2,016 blocks (≈ 2 weeks at 10 min/block)
- Fixed schedule based on block height
- No adjustments between periods

## Network Hashrate

The network hashrate can be derived from the current difficulty:

```
hashrate ≈ difficulty * 2^32 / 600
```


This gives us the approximate hashes per second (H/s) being performed by all miners. The actual hashrate may vary due to:
- Mining luck (statistical variance)
- Changes in active mining equipment
- Network latency and orphaned blocks