In a test match, the start of every innings will see a new ball being used. After 80 overs, the bowling side has the prerogative to replace the ball with a new ball at the start of any subsequent over(once per 80 overs). As you suspect, there are many different variables involved in deciding whether or not to use a new ball. What is undeniable is that a new ball is harder, so it will typically bounce more and reach the batsman faster than an older ball. This typically makes it more advantageous for fast bowlers, and I believe conventional wisdom was to take the new ball as soon as you could. However, depending on pitch conditions, your bowlers, and the opposing batsmen, this may not be true. Older balls can “reverse swing” more if your fast bowler is skilled in that particular branch of voodoo, and spinners can grip older(and rougher) balls better, so you may prefer to keep the older ball for a while.