The twelfth man is the name given to a substitute in cricket. However while in other sports such as football and rugby where substitutes may be used by choice, a twelfth man is only allowed to play if a member of the starting eleven sustains an injury during the match. Law 2 of the Laws of Cricket deals with substitutes, when they are allowed to come onto the pitch and what they are allowed to do. Basically the umpire has to be convinced that a player has been injured since the starting eleven was announced if he is to allow the twelfth man to take his place. If the umpire is satisfied with the legality of a substitution then the twelfth man is allowed to take the place of the injured player but only to field. The twelfth man is not allowed to bowl, bat or keep wicket. This is to prevent a team from using one player to bowl and another to bat, thus giving them a significant advantage. If a player is off the field for more than 15 minutes then when they return they are not allowed to bowl until they have been on the field for the same length of time that they were off it.
Despite the strict law governing when a player can be substituted it is common these days for bowlers to take "rests" for up to 30 minutes following a particularly strenuous bowling spell. This simply involves them claiming to have a slight niggle that they think should be treated. The advantages for the fielding side are that a fresh and more athletic fielder can come onto the pitch and their primary fast bowler gets a nice rest. It is likely that you will see this happen in almost every international test match played these days.
In international games it has become traditional for the twelfth man to be a player of the local team whose home ground the match is being played at. Often a young player or possible future addition to the squad is used as the substitute fielder. This fielder is often different from the twelfth man named in the squad who is there to step in in case of injury rather than act simply as a substitute fielder.
Being twelfth man is a well known booby prize in school or low level cricket. The player must turn up to the match with very little hope of playing. Once there they are frequently pressed into the less desirable roles such as scoring, making the tea or looking after the kit. In school cricket the rules are more lax and the twelfth man will often be brought on to field for part of the game to try and include him rather than force him to sit by all afternoon. To be selected twelfth man is almost worst than being dropped. It is essentially a non-playing role, designed not for those close to actual selection but for those who are willing or enthusiastic enough to turn up and score.