I am trying to get my head around how blockchains work.

I have two blocks in my blockchain:

Block #0 has been added to the blockchain!
Hash: b3bc62c2b75e70fcc3fe709a5e724c7230d89bb70db17c1d2f5c3687b44b4c31
Block #1 has been added to the blockchain!
Hash: 76915298f65b261dbe8b5e2300c77b13966a8dd68175e49ffe5cbc59b055042d

The hash is derived from passing the block's timestamp, data and the previous block's hash through sha256. I understand that if I am in the middle of a blockchain and then try to modify the data the other blocks will be corrupt because the hash won't be correct. E.g. I modify block 2, change the data and even generate a new hash using the correct function, this will invalidate block 3's hash because the previous hash won't generate the correct hash for block 3.

However if I modify the last block in the chain how does it work? I can just change the data and generate a new hash, there is no next hash to verify it.

Any clarification on how this works would be great! Thanks!

1 Answer 1


It's true, you can have two different valid blocks (with different hashes) that both refer to the same previous block. Call them A and B. Then there are effectively two different branches of the block chain (so it's really a tree rather than a chain). In such a case, each node must make their own decision as to which one to accept. If both are at the end of the block chain, usually each node will choose the one they saw first.

In particular, a miner must decide which of A or B to use as the previous block hash in a new block. Let's say the next winning miner chose A and mined a new block C. Then future miners will prefer to mine on top of C instead of B, since the branch ending in C (which contains A) is longer (has more total proof-of-work) than the one that ends in B. In the long run, the branch containing A will probably be considered as the "true" blockchain. B becomes an orphan block and is disregarded.

If B contained transactions which A did not, and they are otherwise valid, those transactions can be included in C or some later block in the dominant branch, so they are not lost.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.