<ul>
<li>The first blocks had a 50 BTC subsidy</li>
<li>The subsidy of block 0 is unspendable</li>
<li>This subsidy is cut in half every 210.000 blocks</li>
<li>Block height now is 704558</li>
</ul>
<p>This script (in Ruby) calculates the total amount of Bitcoins issued.</p>
<pre><code>#!/usr/bin/env ruby

# first 210.000 blocks get 50 BTC as subsidy.
# for every 210.000 blocks, the subsidy is cut in half.

# global constants
SATOSHIS_PER_COIN = 100000000
BLOCKS_PER_EPOCH = 210000

# given a block height, returns the subsidy for that block
def block_subsidy(block_height)
  epoch = block_height / BLOCKS_PER_EPOCH
  subsidy = 50 * SATOSHIS_PER_COIN
  subsidy &gt;&gt; epoch
end

# get block height from command line or use last block with subsidy
last_block = (ARGV[0] || 6929999).to_i

# total supply, use 0.0 to make it a float
total_supply = 0.0

# starts with 1 since subsidy of block 0 is unspendable
for height in 1..last_block
  total_supply += block_subsidy(height)
end

# show total supply in bitcoins
puts total_supply / SATOSHIS_PER_COIN
</code></pre>
<p>Having said that, there were <a href="https://bitcoin.stackexchange.com/questions/38994/will-there-be-21-million-bitcoins-eventually">some issues in some blocks</a>, so the true total supply will be slightly less than this.</p>

CC BY-SA 4.0
2021-10-11T18:52:12.317Z
2021-10-23T16:06:50.147Z
2021-10-23T16:06:50.147Z
bordalix
<p>I am not able to understand how circulating supply is calculated by websites like CoinGecko. What does circulating supply mean here - is it the number of coins already minted? If so, how is that calculated?</p>

<bitcoin-core><bitcoin-economy>
How to calculate circulating supply of coins in Bitcoin?
Aviral Srivastava
# How to calculate circulating supply of coins in Bitcoin?

(Asked by: username_0 on 2021-10-09)

I am not able to understand how circulating supply is calculated by websites like CoinGecko. What does circulating supply mean here - is it the number of coins already minted? If so, how is that calculated?

**Tags:** bitcoin-core, bitcoin-economy


---

## 1 answers

### Answer by username_1 on 2021-10-11. Score: 1

* The first blocks had a 50 BTC subsidy
* The subsidy of block 0 is unspendable
* This subsidy is cut in half every 210.000 blocks
* Block height now is 704558

This script (in Ruby) calculates the total amount of Bitcoins issued.

```
#!/usr/bin/env ruby

# first 210.000 blocks get 50 BTC as subsidy.
# for every 210.000 blocks, the subsidy is cut in half.

# global constants
SATOSHIS_PER_COIN = 100000000
BLOCKS_PER_EPOCH = 210000

# given a block height, returns the subsidy for that block
def block_subsidy(block_height)
  epoch = block_height / BLOCKS_PER_EPOCH
  subsidy = 50 * SATOSHIS_PER_COIN
  subsidy >> epoch
end

# get block height from command line or use last block with subsidy
last_block = (ARGV[0] || 6929999).to_i

# total supply, use 0.0 to make it a float
total_supply = 0.0

# starts with 1 since subsidy of block 0 is unspendable
for height in 1..last_block
  total_supply += block_subsidy(height)
end

# show total supply in bitcoins
puts total_supply / SATOSHIS_PER_COIN

```

Having said that, there were [some issues in some blocks](https://bitcoin.stackexchange.com/questions/38994/will-there-be-21-million-bitcoins-eventually), so the true total supply will be slightly less than this.


---

