The bitcoin blockchain is a cryptographically secured, time-stamped, public and distributed database of every bitcoin transaction that has ever occurred on the network. “Distributed” here means that the information in the blockchain is broadcast to and recorded by every node in the network. There is no one central database. Any user can refer to this list of transactions and check exactly what how many bitcoins have ever belonged to any specific address at any point in time. This way the system is transparent, double-spending is prevented, and there is no need for a trusted central authority.
The bitcoin blockchain is supported by the efforts of many miners: users who put computing power to the task of solving a mathematical problem that will reward them with bitcoins, while at the same time producing the hashes that secure the blocks of data in the chain. The hashes are cryptographically produced strings of data that make the info in the blockchain virtually impossible to tamper with.
Blockchain technology was originally developed for bitcoin; however, it is the base of other cryptocurrencies, and can be used for any other kind of data recording. The blocks in a blockchain might contain information about identity, dates, or most anything.
How it works
When two users partake in a bitcoin transaction, information about this transaction gets broadcast from their wallets to every other user (node) in the network. This information is digitally signed and time-stamped, so that anybody who looks at it knows who sent the money, who received it, how much money it was, and when. Once the nodes have looked at the information and confirmed the transaction (that is, checked that everything is legitimate), they each update their copy of the blockchain on their computers to include this new data. The data gets packed into a block along with data of other transactions that are happening around the same moment. A block is like a 1 megabyte bundle of chronologically ordered information about transactions.   These blocks will get connected together in order of creation to form the blockchain.
Building the chain
When a new block is being created, the information is contains is passed through a hash function to create a hash. A hash is a unique string of characters that identifies a particular piece of information. For each particular block there is a particular hash, so that hashes are a bit like specialized stamps that can be mathematically linked to their corresponding blocks. It is as if each block had an algorithmically produced ID number or code. No two hashes are alike because no two blocks are alike.
When a new block is added to the (block)chain, the hash from the last block is always included in the data of the new one. This way, each block contains not only information about a specific transaction (in the case of bitcoin) but also a reference to the information of the previous block. And since that previous block also contains the hash of the block that came before it and so on, each block actually references all the blocks that came before it. In other words, a trace of each block is woven into the hash of the following blocks, linking them all together in a chain that goes back to the genesis block.
Because information from each block is contained in all subsequent blocks, tampering with data in any single block would require enough computing power to be able to edit the hashes of all subsequent blocks in the chain. The farther down a block is in the chain, the more computing power would be necessary to edit the data in it. Since blocks are generated at a constant speed of 1 block/ten minutes, it is virtually impossible to edit a block, making fraud and double-spending highly unlikely.
Honest miners will always link new blocks to the last block in the chain, with a hash referencing it. A new block is only considered valid if it has information about all previous chain links, and a copy of the chain is only valid if it starts with genesis block.
Forks in blockchain
Forks are ramifications in the blockchain; points at which a single blockchain splits into two branches that keep growing independently. Normally, blockchains are supposed to be just one long string of chronologically ordered blocks. The order in which blocks get added to the blockchain simply depends on their time-stamp (that is, blocks get added in the order in which they were created). However, if for any reason two or more blocks are created roughly at the same time and the network is unsure in which order they should go, the chain will split into two or more versions of the chain, each one with copies of the same blocks but in different orders. In other words, if multiple blocks appear at the same height in the chain, the new blocks that are created after that will be copied onto the multiple blocks of the split, growing branches to the chain. It is often the case that eventually, by majority choice of the users, all of the new branches are abandoned except for one, which becomes the longest, and therefore the valid chain. That is, when a fork happens, the network of users usually votes on one branch that they will consider the “real” blockchain, and that branch will continue to receive new blocks and grow, while the other branches are abandoned. The abandoned branches are called orphan chains.
However, on other ocassions the split will be permanent, creating two separate blockchains that keep adding blocks and growing, eventually standing for two separate currencies.
Blocks in orphan chains are not used for anything. When users consensually switch to another, longer chain, all valid transactions of the blocks inside the shorter chain are re-added to the pool of queued transactions and will be included in a new block. The reward for the blocks on the shorter chain will not be present in the longest chain, so they will be lost. This is why a network-enforced 100-block maturation time exists before people can use their coins.
Bitcoin forks occur regularly and there are different types.
Because each block can only reference a single previous block, it is impossible for two forked chains to merge.