The process of mining as described in the answer to this question is simultaneously repeated by multiple miners.
Is it possible for two miners to find the next block at the same instant? If it is, what happens if they do?
Bitcoin Stack Exchange is a question and answer site for Bitcoin users, developers, and enthusiasts. It only takes a minute to sign up.Sign up to join this community
Yes, it is possible, and you can actually follow "orphaned blocks" here: https://blockchain.info/orphaned-blocks
Bitcoin clients always trust the longest chain, so if two blocks is mined on the same time, it's up to (51% of) the miners to decide which is going to be 'accepted' and which is going to be worthless.
This is one of the reasons why you shouldn't trust only a few confirms, as the confirms could be a orphaned blockchain. After "enough" confirms, everyone will mine on the "correct" blockchain, because any work(mining) on a orphaned blockchain is waste of power (unless your trying to perform a 51% attack).
What Nicolai said is not completely right. The network would decide which one is the main chain according to the following block mined. Let's assume that block A and B are mined at almost the same time. The miners would accept the first block that was broadcast to them, so there would be some miners accept A and others accept B, it doesn't matter whether A/B is accepted by 51% or more miners or not. Miners accepting A would try to mine the next block on top of A, while other miners accepting B would try to mine the next block on top of B. If next block to be found is on the top of A, then miners mining on the B will turn to the A chain, which is the main chain. BTW, the block B is named as an orphaned block, you can find more on the https://blockchain.info/orphaned-blocks. Of course, there may be a circumstance that the next block is mined at roughly the same time both on top of A and on top of B, then the process mentioned above would circulate again till the problem gets solved. Now you can understand why the new blocks won't be spendable until at least 120 blocks have been built on top of it in a chain.