This is a quote from the book "Bitcoin: A Peer-to-Peer Electronic Cash System" by Satoshi Nakamoto
...ould have to redo the proof-of-work of the block and all blocks after it and then catch up with and surpass the work of the honest nodes. We will show later that the probability of a slower atta
cker catching up diminishes exponentially as subsequent blocks are added.
read full book
To compensate for increasing hardware speed and varying interest in running nodes over time, the proof-of-w
ork difficulty is determined by a moving average targeting an average number of blocks per hour. If they're generated too fast, the difficulty increases.