Desired probability of not stocking out (e.g., 95%)
Recommended Safety Stock0 units
Reorder Point (ROP)0 units
Lead Time Demand0 units
Z-Score (Service Factor)0.00
Combined Deviation0.00
Understanding Safety Stock and Fill Rate
Safety stock is an additional quantity of an item held in inventory to reduce the risk that the item will be out of stock. It acts as a buffer stock in case sales are greater than planned or the supplier is unable to deliver the additional units at the expected time.
The Fill Rate (often referred to as Service Level in this context) represents the probability that incoming demand will be met from the inventory on hand during the lead time. For example, a 95% service level implies that you are statistically covering 95% of the possible demand fluctuations during the replenishment period.
How to Calculate Safety Stock
The standard formula for Safety Stock ($SS$) accounts for two main types of variability: variability in demand and variability in lead time. The formula used by this calculator is:
SS = $Z \times \sigma_{LTD}$
Where:
Z is the Z-score derived from your Target Service Level (inverse normal distribution).
$\sigma_{LTD}$ is the standard deviation of demand during lead time.
The Formula for Combined Deviation ($\sigma_{LTD}$)
When both demand and lead time vary, the formula for the combined standard deviation is:
While safety stock tells you how much "extra" inventory to keep, the Reorder Point tells you when to place an order. It combines expected demand during lead time with your safety stock.
ROP = (Average Daily Demand $\times$ Average Lead Time) + Safety Stock
Why is Fill Rate Important?
Optimizing your fill rate is a balancing act between inventory costs and the cost of lost sales (stockouts). A higher fill rate requires holding more safety stock, which increases carrying costs (storage, insurance, obsolescence). However, a low fill rate risks frustrating customers and losing revenue.
Common Service Level Targets
90%: Common for low-margin or non-critical items.
95%: Standard target for most retail inventory.
98-99%: Used for critical spare parts or high-priority items where stockouts are costly.
function calculateSafetyStock() {
// 1. Get Input Values
var avgDemand = parseFloat(document.getElementById('avgDemand').value);
var stdDevDemand = parseFloat(document.getElementById('stdDevDemand').value);
var avgLeadTime = parseFloat(document.getElementById('avgLeadTime').value);
var stdDevLeadTime = parseFloat(document.getElementById('stdDevLeadTime').value);
var serviceLevel = parseFloat(document.getElementById('serviceLevel').value);
// 2. Validation
if (isNaN(avgDemand) || avgDemand < 0) {
alert("Please enter a valid Average Demand.");
return;
}
if (isNaN(stdDevDemand) || stdDevDemand < 0) {
alert("Please enter a valid Standard Deviation of Demand.");
return;
}
if (isNaN(avgLeadTime) || avgLeadTime < 0) {
alert("Please enter a valid Average Lead Time.");
return;
}
// stdDevLeadTime is optional, default to 0 if empty or invalid
if (isNaN(stdDevLeadTime) || stdDevLeadTime < 0) {
stdDevLeadTime = 0;
document.getElementById('stdDevLeadTime').value = 0;
}
if (isNaN(serviceLevel) || serviceLevel = 100) {
alert("Please enter a valid Target Service Level between 50 and 99.99.");
return;
}
// 3. Calculation Logic
// Calculate Z-Score based on Service Level %
// Service level comes in as 95, convert to 0.95
var probability = serviceLevel / 100;
var zScore = getZScore(probability);
// Calculate Average Lead Time Demand (Mean)
var leadTimeDemand = avgDemand * avgLeadTime;
// Calculate Combined Standard Deviation (Sigma LTD)
// Formula: Sqrt( LeadTime * StdDevDemand^2 + AvgDemand^2 * StdDevLeadTime^2 )
var term1 = avgLeadTime * Math.pow(stdDevDemand, 2);
var term2 = Math.pow(avgDemand, 2) * Math.pow(stdDevLeadTime, 2);
var sigmaLTD = Math.sqrt(term1 + term2);
// Calculate Safety Stock
var safetyStock = zScore * sigmaLTD;
// Calculate Reorder Point
var reorderPoint = leadTimeDemand + safetyStock;
// 4. Display Results
document.getElementById('resultSafetyStock').innerHTML = Math.ceil(safetyStock).toLocaleString() + " units";
document.getElementById('resultROP').innerHTML = Math.ceil(reorderPoint).toLocaleString() + " units";
document.getElementById('resultLTD').innerHTML = Math.ceil(leadTimeDemand).toLocaleString() + " units";
document.getElementById('resultZScore').innerHTML = zScore.toFixed(3);
document.getElementById('resultDeviation').innerHTML = sigmaLTD.toFixed(2);
// Show result box
var resultBox = document.getElementById('resultBox');
resultBox.style.display = 'block';
resultBox.classList.add('active');
}
// Approximation of the Inverse Normal Cumulative Distribution Function
// (Acklam's algorithm or similar approximation is standard for JS)
function getZScore(p) {
// If p is 0.5, Z is 0
if (p === 0.5) return 0;
// Constants for approximation
var a1 = -3.969683028665376e+01;
var a2 = 2.209460984245205e+02;
var a3 = -2.759285104469687e+02;
var a4 = 1.383577518672690e+02;
var a5 = -3.066479806614716e+01;
var a6 = 2.506628277459239e+00;
var b1 = -5.447609879822406e+01;
var b2 = 1.615858368580409e+02;
var b3 = -1.556989798598866e+02;
var b4 = 6.680131188771972e+01;
var b5 = -1.328068155288572e+01;
var c1 = -7.784894002430293e-03;
var c2 = -3.223964580411365e-01;
var c3 = -2.400758277161838e+00;
var c4 = -2.549732539343734e+00;
var c5 = 4.374664141464968e+00;
var c6 = 2.938163982698783e+00;
var d1 = 7.784695709041462e-03;
var d2 = 3.224671290700398e-01;
var d3 = 2.445134137142996e+00;
var d4 = 3.754408661907416e+00;
// Define break-points
var p_low = 0.02425;
var p_high = 1 – p_low;
var q, r;
// Rational approximation for central region
if (p > p_low && p < p_high) {
q = p – 0.5;
r = q * q;
return (((((a1 * r + a2) * r + a3) * r + a4) * r + a5) * r + a6) * q /
(((((b1 * r + b2) * r + b3) * r + b4) * r + b5) * r + 1);
}
// Rational approximation for tail regions
if (p <= p_low) {
q = Math.sqrt(-2 * Math.log(p));
} else {
q = Math.sqrt(-2 * Math.log(1 – p));
}
r = (((((c1 * q + c2) * q + c3) * q + c4) * q + c5) * q + c6) /
((((d1 * q + d2) * q + d3) * q + d4) * q + 1);
if (p <= p_low) {
return r;
} else {
return -r;
}
}