The word blockchain itself is descriptive. Here, blocks of digital information are linked back to one another like a chain of blocks. In the following image, we can see blocks that contain a series of transactions:
If someone tampers with the first transaction of the second block by altering $300 to $3,000, Ashin's balance would have an additional $2,700. Such tampering would lead to disastrous consequences. Hence, blockchain uses cryptography to make itself tamper-proof.
In the following blocks, we have added an additional attribute, the hash:
A hash is a set of characters that represents the contents of the block. It's calculated using a cryptographic hash function. For the sake of simplicity, we have made a simple hash by taking the first letters from the names of senders and beneficiaries. We also added the amount transferred in the middle of those first letters, and hence the hash for the first block is J500JJ450A. (Technically, this is not how a hash function works, but you get the idea.)
Since the first block has no preceding block, its previous hash field is not applicable. However, from the second block, all successive blocks have stored the hash of its previous block.
If someone tries to tamper with the first block and change John's transfer from $500 to $5,000, the hash of that block changes from J500JJ450A to J5000JJ450A. However, the successive block has already stored the hash as J500JJ450A. This mismatch would break the chain. Hence, the purpose of the hash is to ensure that blocks are not tampered with.
What if someone tries to change a block and the hash of all the succeeding blocks?
Different blockchains have different mechanisms to protect themselves from such situations. In the Bitcoin system, before a block is added to the chain, certain computationally intense tasks must be carried out.
Blocks are only confirmed once proof of running such intensive tasks or proof-of-work is shown. Hence, if a hacker wants to modify the hashes of n blocks, they need to run such computationally intense tasks n times to show the proof-of-work. Considering the present limits in computation, this scenario are highly unlikely.
Secondly, blockchain systems are decentralized. This means that a blockchain program isn't executed by a single computer, but all the computers in its network work collectively in executing its instructions. The data in the blockchain is also replicated in all the computers present in the network. Hence, the system would consider only what the majority say is correct.