Often a blockchain can have some flaws, bugs or it just needs improvements. To fix those vulnerabilities the blockchain has to be forked.
A fork rewrites the rules which a full node must follow in order to consider a block valid. A full node can decide either to accept the new rule (updating its software) or reject it.
If some nodes choose to support the fork while others choose not to do so, then a blockchain fork might happen: in this case the blockchain splits up in two different branches.
The two blockchains share the same chunk of chain from the genesis block to a certain block before the divergence.
There are two kinds of fork: hard fork and soft fork. Both hard and soft forks can cause a blockchain fork.
When a fork happens, the choice made by the community is crucial because it can weaken the blockchain. When the community of the full nodes split then each branch of the blockchain created by the split will have less hashpower: so both blockchains become weak to a 51% attack.
If the community cannot make a strong decision about the fork, then also the community itself can become weak; this could lead to bad consequences regarding the trust on the platform: the reliability of the platform will decrease and the interest of investors and developers will move away.
Let’s take some real examples.
Before August 2017, the bitcoin community was discussing how to improve the bitcoin transaction performance (aka scalability). The community had two different opinions:
- to increase the block size to 8MB
- to store the data within a block with a method called SegWit 
In August 2017 the bitcoin blockchain split up in two branches: Bitcoin Cash  with an increased block size to 8M and Bitcoin that uses SegWit.
In 2016 an attacker managed to use the vulnerability of ethereum security for his own good and many people lost their investments . Within the ethereum community there were two ways to solve this problem:
- to revert the transactions due to the flaw
- not to make any changes, keeping the original protocol
In July 2016 the ethereum blockchain forked into Ethereum (with the flaw fixed) and Ethereum Classic (original protocol) .
What is the difference between hard fork and soft fork?
Soft fork: a block created with a new rule is considered valid also by the old rule; this means a soft fork is forward compatible (in other words the blocks created with the new rule are compatible with the blocks created with the old rule but not the other way around).
Example: you have a blockchain where each block has a maximum size of 2MB; then you apply a soft fork to reduce the maximum size of the block to 1MB. The old rule will consider the blocks created with the new rule valid since they do not exceed the 2MB maximum size.
Hard fork: blocks created with the new rule are not considered valid by the old rule; this means that a hard fork is not forward compatible (the blocks created with the new rule are not compatible with the blocks created with the old rule).
Example: a blockchain has the block size limit of 1MB; then a hard fork is applied in order to increase the block size limit to 3MB. The blocks created with the hard fork rule are not compatible with the old rule since the 3MB limit exceeded the 1MB limit but the old blocks are still compatible with the new rule.
SOFT FORK: how does the blockchain fork happen?
If the hashpower of the full nodes that accepted the soft fork is 51% or more, then there will be no blockchain fork.
If less than 51% of the hashpower comes from the full nodes which do not support the soft fork then the blockchain will split: a branch of blocks will be created by the nodes following the old rule (since the old rule is not compatible with the new rule) and another branch of blocks by the nodes following the new rule.
If the full nodes start upgrading their software to the soft fork and the hashing power supporting the soft fork is more than 51%, then all the network (both supporting and not supporting the fork) will consider the blockchain branch created with the soft fork rule as true.
This is possible because the branch created with the soft fork became longer than the other branch; since the soft fork branch is compatible with the old rule, all the network will consider the longer branch valid and there will be one single branch.
HARD FORK: how does the blockchain fork happen?
Here we have to consider two cases.
Case 1: 51% of the hashpower of the network do not update their software to the hard fork.
Since the blocks created with the old rule are compatible with the hard fork and the blockchain branch supported by the old rule grow faster (because it has more hashpower), then the blockchain branch supported by the old rule is considered valid and there is no blockchain split.
Case 2: 51% of the full nodes update their software to the hard fork but a smaller percentage is still using the old rule.
In this case the blockchain will split: since the blocks created with the hard fork rule are not compatible with the old rule then there will be a branch supported by the nodes following the old rule and a branch supported by the nodes following the hard fork.
Obviously in case when 100% of the community supports or does not support the hard fork there will be no blockchain split.
 The stolen ether and the birth of Ethereum Classic:
 51% Attack