It's all dependent on the situation.
How much time is left?
How much am I up by?
How many timeouts does my opponent have left?
How well has my opponent been moving the ball?
Can I trust my defense to secure the game for me?
Other Ppl may have different questions that they may ask about that example. There's always more to it than just oh it's 4th and 5 in the 4th quarter, better punt.