The minimum safe following distance is around two seconds behind the vehicle in front. A good way to measure this is to watch the vehicle in front of you as it passes a fixed object such as a bridge, a tree, or a road sign. At least two seconds should have elapsed before you vehicle passes the same object. To measure two seconds, you can say to yourself: "Only a fool breaks the two second rule." Don't say it too fast!
Two seconds should be considered an absolute minimum gap. In wet weather this figure should be doubled, providing a gap of least four seconds. In foggy or icy conditions the basic following distance needs to be multiplied by up to ten times in order to achieve a safe gap.
If the vehicle in front of you should suddenly stop, you need to have enough time to react to what is happening and stop safely. When you maintain an adequate gap in front, it is not necessary to break harshly. This, in turn, allows the driver behind you sufficient time to assess the situation and respond accordingly.
This is an example of how a good driver can avoid the need to carry out an emergency stop and why this is important for safety. You may be closer to the vehicle in front and, if you are paying attention, there might still be enough time to stop. But there would be a greater risk of losing control. And would the driver following you be able to stop in time? Perhaps the driver behind you is not paying full attention. Are you willing to take that risk?
If the following vehicle is too close (tailgating) simply ease off the gas a little and increase the gap between you and the vehicle in front, to say 3 seconds. So that you still have that safe 4 second bubble around you, so if the car in front brakes you don't have to brake as hard. With tailgaters you can't change their behaviour but you can still drive safely.