For simple explanation of safety stock, it can be said that the calculated safety stock is the difference between the sales forecast and the upper limit. This is in fact not true since there are more things that affect the calculations. Mostly it depends on how predictable the product is in sale, how well fitted the model is, the lead time, the cumulated confidence level for each lead time (normally distributed), the forecast and set service level.
In further details, safety stock calculations are used in addition to forecasts and confidence limits. This is most often used in setting inventories which are replenished only at certain variable or fixed intervals.
It is not very complicated to calculate the expected demand, but it is a lot more complicated to find the probability that the sales will exceed the cumulative forecast by some certain amount. This depends upon the details of the statistical forecast model. The difficulty of the calculation lies in considering the serial correlations of sales from point to point over the reorder cycle.
The solution to this is to convert the model to a form called the Wold representation. This is the key to determining the statistical distribution of the cumulative forecast. This does though assume that the statistical distribution of future sales is in fact correctly captured which is in fact never absolutely true since the model does not actually capture the true model.
The model will also assume it is equally likely for the demand to be above or below the forecast. To fix that upper and lower confidence limits provide the model with information about the spread around the forecast. This is important to know to calculate the safety stock. For example, a model that predicts 757 units in demand and has a 95% upper confidence level set as 875 units is in fact saying that there are 95% chance of demand being lower than 875 units. Note that the upper limit of sales forecasts is calculated from the set service level and variations in sale.
Those calculations do not take to account lead times but to determine economic order size and reorder point for some desired service level it is crucial to take lead time into account. The expected demand during lead-time (DDLT) is the cumulative forecast. Safety stock is the excess stock needed, above and beyond the DDLT, to maintain the service level specified for the upper confidence limit. The safety stocks are output for each lead-time up to and including the forecast horizon. Thus you would add together the DDLT and Safety Stock values for lead-time. This quantity is known as the Reorder Point. If your stock falls below the Reorder Point then you do not have enough stock to satisfy the expected demand at the specified service level and need to reorder.