- For the subscription TV package, see MLB Extra Innings.
Ordinarily, a baseball game consists of nine innings, each of which is divided into halves: the visiting team bats first, after which the home team takes its turn at bat. However, if the score remains tied at the end of nine complete innings, the rules provide that "play shall continue until (1) the visiting team has scored more total runs than the home team at the end of a completed inning; or (2) the home team scores the winning run in an uncompleted inning." Because they bat in the second (or "bottom") half of an inning, a home team which scores to take a lead either in the ninth inning or at any point in extra innings immediately ends the innning and the game with a win for that team. Usually, the home team wins by only 1 run in this situation; but if the hit is a home run which leaves the playing field, all runners and the batter are entitled to score, with their runs counting in the final score even if it puts the home team ahead by more than 1 run. (Here, a grand slam with the score tied would put the home team ahead by 4 runs.)
The rules of the game, including the batting order, availability of substitute players and pitchers, etc., remain intact in extra innings. Managers must display caution to avoid using all their substitute players, in case the game reaches extensive extra innings.
The record for the most innings ever played in a single professional game is 33, occurring in a minor-league game in 1981. (Many more details on this game can be found here.) The longest game by innings in Major League Baseball was a 1-1 tie in the National League between the Boston Braves and Brooklyn Dodgers in 26 innings, at Braves Field in Boston on May 1, 1920. It had become too dark to see the ball (fields did not have lights yet and the sun was setting), and the game was considered a draw.
The longest American League game, and tied for the longest major league game by innings which ended with one team winning, was a 7-6 victory by the Chicago White Sox over the Milwaukee Brewers in 25 innings, at Comiskey Park in Chicago in 1984. The game was begun at 7:30 p.m. on the evening of May 8, and after scoring early runs both teams scored twice in the 8th inning; but the game was suspended after 17 innings with the score tied 3-3 due to a league rule prohibiting an inning from beginning after 12:59 a.m. The game was continued the following evening, May 9, and both teams scored three times in the 21st inning to make the score 6-6; finally, in the bottom of the 25th, the White Sox' Harold Baines hit a home run to end the contest. Tom Seaver was the winning pitcher in relief. (A regularly scheduled game followed, meaning both nights saw 17 innings played; Seaver also started, and won, the second game.) The official time of the entire 25-inning game was 8 hours 6 minutes, also a major league record. 
On September 11, 1974, the St. Louis Cardinals won a marathon night game against the New York Mets, after seven hours four minutes, and 25 innings, also tied for the longest game to a decision in major league history. Two Mets errors led to the Cardinals' winning run, starting with an errant pickoff throw that allows Bake McBride to scamper all the way around from first. St. Louis won, 4–3. The Mets went to the plate 103 times, a record in a major league game; the Cards were not far behind with 99 plate appearances. All told, a record 175 official at-bats were recorded, with a major-league record 45 runners stranded. Only a thousand fans were left on hand at Shea Stadium when the game ended at 3:13 a.m. ET. This was the longest game played to a decision without a suspension.
The longest major league postseason game was an 18-inning contest played between the Atlanta Braves and the Houston Astros on October 9, 2005. In the fourth game of a National League Division Series at Minute Maid Park in Houston, the Braves (who were trailing the series by 2 games to 1 and facing elimination) took a 6-1 lead into the 8th inning. A grand slam by Lance Berkman in the bottom of the 8th brought the score to 6-5, and in the last of the 9th Brad Ausmus homered to tie the game and send it to extra innings. The score remained deadlocked at 6-6 until the 18th, when the Astros' Chris Burke (who entered the game in the 9th inning as a pinch runner) homered to left field to win the game and send Houston to the National League Championship Series against the St. Louis Cardinals. Roger Clemens, who was brought in to pinch-hit in the 15th and pitched the last three innings in relief, was credited as the winning pitcher in the 5 hour, 50 minute contest.
The longest World Series game by time was Game 3 of the 2005 Series, played between the Chicago White Sox and the Houston Astros on October 23, 2005: it ran 5 hours and 41 minutes. It was also the longest World Series game by innings (14), tied with Game 2 of the 1916 Series, played between the Boston Red Sox and the Brooklyn Robins on October 9, 1916. The 1991 World Series was the longest World Series ever in terms of total number of innings, running out to seven games, three of which were extra-innings contests (the longest of which ran out to 12 innings), a total of 69 innings before the trophy was finally claimed by the Minnesota Twins.
The concept of extra innings does not exist in cricket: a match that ends with both sides all out with an identical number of runs is a tie. Due to the high-scoring nature of the game, tied matches are very uncommon, having occurred only twice in the history of Test cricket and rarely in other levels of the game. Much more common is a draw, which occurs if no result is obtained before the scheduled end of the match.
In the Japanese baseball leagues (Nippon Professional Baseball), games go no longer than 12 innings. Games that are still tied after 12 innings are officially declared ties and are reflected in the team's record.