A pit stop takes about two to three seconds stationary, but the whole visit - slowing for the pit lane, the stop, rejoining - costs somewhere around twenty seconds against staying out. Strategy is the art of making that loss work for you.
One stop or two?
Each extra stop costs ~20 seconds. Fresh tyres are faster. The question is whether the time gained over the remaining laps beats the time lost in the pits. If Degradation is low, one stop wins. If tyres fall away quickly, two stops can be faster overall.
The undercut
You are stuck a second behind a rival. You pit first. On fresh tyres your next laps are much quicker than theirs on worn rubber. When they pit a lap or two later, you have made up the gap - and they come out behind. That is the Undercut.
The overcut
Sometimes staying out is better. If fresh tyres take a few laps to warm up, or the pitting car rejoins into traffic, the car that stays out in clear air can build enough time to pit and still come out ahead. This is the Overcut, and it tends to work on tracks where tyres are hard to bring up to temperature.
Reacting to safety cars
Under a safety car the whole field slows down, so a stop costs perhaps half the usual time. Teams whose drivers have not stopped yet usually pit immediately. A driver who already pitted a lap earlier can lose a lot through bad luck alone.
Who decides
The race strategist and race engineer make the call, informed by live models of every car’s tyre wear and gap. The driver can push back - they can feel the tyres - and some of the best races are a negotiation over the radio.