What makes the blockchain so immutable?

It'shash functions.

Every arrow ← in the blockchain above represents the result of invoking a hash function. Blocks don't just contain transactions; each block also contains in itself the hash value of the previous block. This hash value, or just hash for short, is the result of applying a hash function to all of the data in that block, including the hash of the block before it.

Let's have a look at what hash functions do! Below you can play around with SHA-256 - the specific hash function used by Bitcoin. SHA-256 is a cryptographic hash function. Among other things, this means that it's basically impossible (with today's computers) to find two inputs that have the same hash. But feel free to try...

hexbinary
e3 b0 c4 4211100011 10110000 11000100 01000010
98 fc 1c 1410011000 11111100 00011100 00010100
9a fb f4 c810011010 11111011 11110100 11001000
99 6f b9 2410011001 01101111 10111001 00100100
27 ae 41 e400100111 10101110 01000001 11100100
64 9b 93 4c01100100 10011011 10010011 01001100
a4 95 99 1b10100100 10010101 10011001 00011011
78 52 b8 5501111000 01010010 10111000 01010101

How does this work exactly? Well this is a question for a cryptography course... The important thing to remember is that cryptographic hash functions help us maintain the integrity of data. If we keep the hash of a bunch of data in a safe place, we can be pretty much certain that no one can modify the data, not even a tiny bit, without us noticing afterwards. We only have to hash the data again and compare the result with the hash we kept safe.

By trusting that the hash of a given block is correct* we can always check that all blocks up to this block are in exactly the same state as they originally were. Because whenever we change something, for example the value of a transaction included in a given block, we also change the input to our hash function, and hence - with near certainty - also the resulting hash. The blockchain is, in its essence, a hash chain.

Blocks for which the hashes don't match simply get rejected. We either have no blocks, or we have blocks that weren't changed. And therefore one could say that the blockchain is immutable**.

* This trust is earned at the consensus layer.

** We can still switch to a different chain of course, respectively to a different fork of the blockchain. This can also happen by accident, if something on the consensus or network layers goes wrong. The security of each layer in our model always depends in some way on the security of the layers below.

A note on cryptography...

Cryptography is hard. It's very easy to build something that you think is secure, but which just isn't. Don't roll your own crypto* - use what is crafted by cryptography experts and battle-tested in practice! And if some project you like does invent it's own cryptography - a healthy dose of scepticism won't hurt...

* The original meaning of "crypto" if of course "cryptography". What did you think?