Definition
The infinite monkey theorem is a thought experiment from probability theory: if infinitely many monkeys hit typewriter keys at random forever, the probability that they eventually type a Shakespeare play or a perfect book becomes 1 (100%). It shows that if you repeat independent tries endlessly, and each try has the same chance of success that is greater than 0, then even the rarest event will happen with probability 1 (almost surely).
A Monkey at the Typewriter and the Power of Infinity
Close your eyes and mash a keyboard at random. What are the odds you'd type the word "apple" by accident? If the keyboard has about 50 keys, hitting those five letters in exactly the right order is roughly a 1-in-300-million shot. If one short word is that hard, writing a thick book with tens of thousands of words by pure luck is almost impossible to imagine.
But in the world of math, once you are given infinite time and infinite chances, everything flips. As long as the chance is not exactly 0, even a ridiculously tiny chance works out the same way. Multiply the chance of failing by itself again and again, forever, and the chance of always failing shrinks toward 0.
If you flip a coin enough times, there will eventually be a moment when heads comes up a hundred times in a row. In the same way, with infinite tries, even the most unbelievable fluke becomes an event with probability 1, meaning one that is practically unavoidable. Mathematicians say it happens "almost surely."
To Be Precise: In the Real Universe, It's Practically Impossible
The infinite monkey theorem is just a logical thought experiment for explaining a math idea. In the world we actually live in, the odds are so small that you could never expect it to happen. That's because the time and matter we can use are finite. The universe is only about 13.8 billion years old, and the matter in the observable universe is limited too.
Let's say you have a typewriter with 50 keys, counting letters, spaces, and punctuation. Even if you only want a short passage from Shakespeare's Hamlet, about 60 characters, typed correctly at random, the odds are 1 in 50 to the 60th power. The bottom number of that fraction is far, far bigger than the number of all atoms in the observable universe (about 10 to the 80th power).
Suppose that over the 13.8 billion years since the Big Bang, every grain of sand in the universe turned into a monkey and each one hit the keys thousands of times a second. The chance of finishing even one meaningful book would still be close to 0. In the end, this theorem isn't about what's possible in reality. It's an illustration of the power of infinity as a mathematical tool.
A Common Mix-Up: Evolution and the Origin of Life
Some people misuse this theorem to argue against evolution. They say, "Just as monkeys can't write a book by typing, complex living things can't come from simple chance." But evolution by natural selection works in a completely different way from plain random typing.
In the infinite monkey theorem, every mistake means starting over from the beginning, and each try is independent. In biological evolution, helpful variations are more likely to be passed on and spread to the next generation. The variations that survive pile up over time in a process called "cumulative selection."
In typewriter terms, it's like locking in each letter once it happens to come out right, and then only retyping the next letter. With this kind of building up, even a random search can produce complex, finely tuned genetic information at a surprisingly fast pace. Still, this comparison only shows that cumulative selection is far more efficient than pure randomness. Real evolution has no target sentence it is aiming for. It just slowly stacks up whatever changes help survival and reproduction in the environment of the moment.
Common misconceptions
Given enough time, a real monkey at the zoo could eventually type out Hamlet.
In reality, the time and matter we have are finite (the universe is only about 13.8 billion years old), so it is practically impossible. The theorem is not about what real monkeys can do. It holds only under the imaginary condition of mathematical "infinity."
Where you meet it
If you flip a coin over and over, then no matter how unlikely it seems, a moment will eventually come when heads shows up 20 times in a row.
If you keep entering a four-digit PIN at random and you have infinite chances, the lock will almost surely (with probability 1) open at some point.
In one sentence
If you repeat independent tries endlessly, each with the same chance of success above 0, even the rarest event happens with probability 1. This theorem shows the power of mathematical infinity, not what is possible in reality.