An infield fly is any fair fly ball (not including a line drive or a bunt) which can be caught by an infielder with ordinary effort when first and second or first, second and third base are occupied, before two men are out. The rule is in place to protect against a team allowing a shallow fly ball to drop in with the intention of causing a force play at second and third or second, third and home. Otherwise, the team would be able to force out baserunners who had stayed put on a routine fly ball.
In these situations, the umpire will declare "infield fly" for the benefit of the baserunners as soon as it is apparent that the fly ball qualifies as an infield fly. The batter is out even if the ball is not caught, and the baserunners can advance at their own risk. If the ball is caught, the baserunners can attempt to advance as they would on a typical ball caught in the air.