Basically, the faster the stage goes, the longer the cutoff time. Also, the harder the stage, the longer the cutoff time. The sprinters tend to calculate the cutoff time for the mountain stages so that they just get in under the time limit.
Every once in a while the sprinters get it wrong and the whole group faces elimination. The Tour organizers have put in a codicil to the rule book allowing them to adjust the cutoff time if more than 20 percent of the starters of a particular stage may be eliminated by missing the time cut.