Tagging up is a rule in baseball that prevents a base runner from advancing bases while the baseball is flying through the air. Tagging up is something base runners do when there are less than two outs, and a batter hits a fly ball (a baseball that is hit high and into the outfield). If an outfielder catches the baseball, the runner must touch the base he was previously at. Once the baseball is caught by the fielder, the runner is cleared to go and will try advancing to the next base. If the runner advances without tagging up once a fly ball is hit, and the baseball is caught, the runner must go all the way back to his previous base before the fielder at that base gets the baseball. The reason the runner must go back to his base if the baseball is caught is because he is not entitled to that next base, since the batter is out and cannot advance. However, if the runner tags up, he can take advantage of the baseball being so far in the outfield to run safely to the next base.
Sometimes, if the runner can clearly tell that an outfielder is not going to be able to catch the baseball, he will advance bases without tagging up, since he predicts it will be a fair hit which entitles him to the next base anyway. However, this is something of a gamble. If the baseball is caught by the outfielder, he must run back to his previous base and risk being thrown out.
Tagging up is usually only done when there are less than two outs. If there are two outs, the runner will usually just run to the next base without tagging up. If the baseball does end up being caught, the half-inning will be over and the base runner's position won't matter anymore. If it doesn't get caught, then the runner will have had a good lead in advancing the bases.
Tagging up exists to keep the game fair. If a player was able to run the bases while the ball was flying in the outfield and being caught, they might be able to get much farther than if they had to wait for the ball to be caught before they could leave the base. If they did not have to tag up, batters could try to hit the ball as high as possible to give their runners time to go around the bases. This rule gives the outfielders a chance to throw other runners out once they catch the ball.
When there are two outs, if the outfielder catches a fly ball, it will be a third out and the inning will be over. That means that whatever players were on base will not be able to run home. So, with two outs, players will run the bases in the hopes that the outfielder will make an error. This way, they are closer to home just in case.