Abrupt increase in difficulty of proof-of-work

I am simulating a private bitcoin network that I started with the initial difficulty set to (1/2)^16, however after about 20 blocks of mining on the network it increased to 1 and has been constant since then. As far as I understand from the source code, it is supposed to increase after every 2016 blocks, so how did it increase after only 20 blocks.

Change of powLimit in my bitcoind instances.

strNetworkID = "regtest";
consensus.nSubsidyHalvingInterval = 210000;
consensus.nMajorityRejectBlockOutdated = 75;
consensus.nMajorityWindow = 100;
consensus.powLimit = uint256S("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
consensus.nPowTargetSpacing = 10 * 60;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = false;
• Are you sure it didn't say difficulty 1 all along? On Bitcoin mainnet, difficulty is equal to the maximum (least difficult) target divided by the current target; if you set your minimum target to x and it's still at x, then that would also be a relative difficulty of 1. Nov 2, 2015 at 17:13
• @DavidA.Harding yeah I figured that out later from the bitcoin documentation. Thanks. Nov 3, 2015 at 3:04
• Cool. Turned it into an answer. Nov 3, 2015 at 4:01

The network difficulty is equal to the maximum allowed (least difficult) target divided by the current target; if you set your minimum target to x and it's still at x, then that would also be a relative difficulty of 1.

An easy way to confirm this is to look at the calculated difficulty for your genesis block (or block 1 if you got your genesis block from somewhere else).

bitcoin-cli getblockhash 0
bitcoin-cli getblock <hash_from_above>

If it also says difficulty is one, then you know difficulty hasn't changed since you started mining.

As an interesting side note, as of (I think) Bitcoin Core 0.11.0, Bitcoin's regtest supports "instant" block generation even though its official maximum target is much lower (more difficult). This means that it has difficulties far below 1:

\$ bitcoin-cli -regtest getmininginfo
{
"blocks": 0,
"currentblocksize": 0,
"currentblocktx": 0,
"difficulty": 4.656542373906925e-10,
"errors": "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications",
"genproclimit": -1,
"networkhashps": 0,
"pooledtx": 0,
"testnet": false,
"chain": "regtest",
"generate": false
}