When taking their position at the beginning of an inning or when relieving another pitcher, pitchers are permitted to throw as many warmup pitches as they want within the countdown parameters set forth by Major League Baseball.
The time between innings and pitching changes is 2 minutes, 5 seconds for local broadcasts, 2 minutes, 25 seconds for nationally televised games and 2 minutes, 55 seconds for tiebreaker and postseason games. The umpire's signal for the final warmup pitch comes at the 25-second mark and the pitcher must throw it before the clock hits 20. The batter will be announced at the 20-second mark and the pitcher must begin his windup to throw the first pitch of the inning within the five seconds before the clock hits zero.
The timing clock also applies to pitching changes and begins as soon as the relief pitcher crosses the warning track (or the foul line for on-field bullpens). Players can be excused from these time limits if a delay in normal warmup activities occurs due to no fault of the players, or the umpire believes a player would be at legitimate risk of injury without receiving additional time.
For between-innings breaks, the timer begins when the final out of the inning is recorded, with several exceptions. If the pitcher is on base, on deck or at bat when the inning ends, the timer begins when the pitcher leaves the dugout for the mound. If the catcher is on base, on deck or at bat when the inning ends, the timer begins when the catcher enters the dugout (another catcher can begin warming up the pitcher). If the final out of the inning is subject to replay, the timer begins when the umpire signals the out. And for any extended between-innings event previously approved by the Office of the Commissioner (such as the playing of "God Bless America"), the timer begins at the conclusion of the event.
Should a pitcher enter the game to replace one who was removed due to an injury or another emergency situation, he is granted as many warmup pitches as the umpire allows.
History of the rule
Prior to 2018, pitchers were granted up to eight warmup pitches under typical circumstances that didn't include an injury or another emergency situation.
Watch: MLB.com explains the rule pertaining to warmup pitches.