The ball in and out of play is the ninth law of the Laws of the Game of association football, and describes to the two basic states of play in the game.
The ball remains in play from the beginning of each period to the end of that period, except when:
The first criterion can be phrased as "all of the ball must cross all of the line" and is of particular importance in decisions regarding goals. The question of whether the ball has crossed the line has often caused controversy in high-profile matches, such as in the example of Geoff Hurst's goal in the 1966 World Cup Final, that put England 3-2 up over West Germany in extra time.  The Law specifically notes that the ball remains in play if it rebounds off a goal frame or corner flag onto the field, or in any case of the ball touching a match official that is not mentioned above.
When the ball is in play players may play the ball, contest the ball, and goals may be scored. Players are liable to punishment for committing fouls. Substitutions may not occur whilst the ball is in play.
In the case a foul is committed or misconduct occurs, the referee may "play advantage" and elect to allow play to continue if the team of the player who was victimized would be benefited if play were to continue. Once play has stopped, the referee may choose to issue punishments.
When the ball becomes out of play, the ball is put back into play by the appropriate restart. The restarts in football are:
Once the ball is out of play, the only restart is the restart appropriate for the reason the ball went out of play in the first place; subsequent actions do not change the restart. For example, if the ball goes out of play because of a foul by Team A against Team B, the restart must be a free kick to Team B even if a Team B player strikes an opponent; offending Team B player would, however, be liable for misconduct (i.e. yellow card or red card).
Note, however, that the referee may change the original restart if he realises he has made an error or on the advice of his assistant referees, provided play has not yet restarted. For example, if the ball has gone out of play because the ball was kicked into goal by Team A and the referee has signalled that a goal has been scored, but then notices that an assistant referee has indicated a foul by a Team A player immediately before the goal was scored, the referee would change to the correct restart of a free kick to Team B where the foul occurred.