Holding the ball, the lead, and a first down late in the game, your team wants to run out the clock and end the game. How much time can they safely run off without giving the ball back to the opposing team?
In the NFL, timing rules ensure that exactly 40 seconds elapse between plays, so a team with a first down just inside the two-minute warning can kneel three times to end the game without needing a fourth down snap, if the defense is out of timeouts. This assumes the offense uses the entire 40 second play clock between snaps (reasonable since a delay of game penalty is basically harmless), but it also assumes the kneel plays themselves take no time at all, so the two assumptions tend to average out. If the defense does have a timeout or the first down snap occurs just before the two minute warning, then the challenge for the offense is a little tougher, and the time taken by the plays themselves becomes important.
As long as the offense has plenty of field position to sacrifice, about ten seconds seems like a reasonable maximum amount of time for a football play. Starting with 2:01 on the clock, ten seconds of giving ground and running in circles on first down would leave one minute and fifty one seconds on the clock at the two minute warning. Repeating the process twice more burns another one hundred seconds, leaving eleven seconds remaining before the snap on fourth down. Roughly the same amount of time remains starting with a first down snap inside of two minutes with an opponent holding one timeout, or inside of one minute twenty seconds with two timeouts, or inside of forty seconds with three. At this point the offense has to be absolutely sure they will burn off all the remaining time with their fourth down play, or the clock will stop on the change of possession and their opponent will get one play on offense.
There are all kinds of creative ways to design a play to burn time. Ten offensive players can surround the ballcarrier in a kind of muddle huddle, preventing him from being tackled or touched down. Or, after a few seconds of running around, the ball could be thrown high into the air, preferably toward the opponent's endzone where it could only result in an incompletion or a long interception. The simplest approach, though, is probably just to commit holding. If each offensive player other than the ballcarrier can effectively hold his defensive counterpart (i.e., tackle him), then only one defender will be left to tackle the ballcarrier. The ballcarrier then has a very good chance of running around and/or backward long enough to kill the remaining time on the clock. A game can't end on an (accepted) defensive penalty, but it can end on an offensive one, because a holding penalty results in a yardage penalty and a repeated down. So by accepting a holding penalty on a play when the game clock expires, the defense only forces a final, untimed down, which would be a kneeldown to end the game.
In fact, as long as ten defenders are being pinned to the ground by offensive players, the ballcarrier may as well run for a first down or touchdown, forcing the defense to accept the penalty and repeat the down even if the play ends with time on the clock. This approach works even before the last play of the game, allowing a theoretically infinite amount of time to be killed off the clock. Of course, if the defensive players know that the offensive players are going to try to tackle them, they will run to avoid the tacklers, but if they are too successful at getting away from the offensive players they will leave receivers open for an easy score.
So, here's how your team should run out the clock: if the amount of time remaining is less than 120 - 40t seconds, where t is the number of opponent timeouts, kneel it out. If the amount of time remaining is less than 121 - 40t, run around and backwards as necessary on the four kneeldown plays. If there's more time on the clock than that, tackle everyone on defense and run for a first down, and repeat until one of the above two situations applies. The only real danger here is being called for "Palpably Unfair Act," which allows the officials to award any penalty they see appropriate. Since one of the qualifying criteria for the Unfair Act penalty is "any act which, in the opinion of the referee, tends to make a travesty of the game," repeatedly committing blatant holding would seem to qualify. In practice, however, referees are very hesitant to call the Unfair Act penalty (to my knowledge it has never been called in the NFL, though there have been examples at lower levels), even for incidents such as a coach on the sideline interfering with the play on the field. So it seems likely that for at least the first instance of the tackle everybody play, the officials would probably award the simple ten yard penalty rather than a more creative punishment like a loss of down or putting time back on the clock.
In NCAA football, the lack of a two-minute warning means the offense can effectively kneel it out from about two minutes and forty seconds, assuming they burn ten seconds per kneeldown play. All other considerations are the same.