A modern CPU fills its multi-stage pipeline by guessing, correctly around 95 to 99 percent of the time, which way an if-statement is going to go before it actually knows the answer. That guess is what branch prediction is, the guess going wrong is a pipeline flush that costs 15-20 wasted cycles, and the 2018 discovery that the guess leaves observable side effects even when it's wrong is what Spectre exploits.
Computer-Architecture
-
Branch Prediction