Sigmoid Function Calculator
Compute the logistic sigmoid σ(x) = 1/(1+e⁻ˣ), its derivative σ′(x), or its inverse logit — for one value or a whole list. Numerically stable, plotted as an S-curve, with a step-by-step derivation, and verified against PyTorch. No signup, runs in your browser.
How it works
The sigmoid — also called the logistic function or expit — squashes any real number into the open interval (0, 1). It is the activation behind logistic regression and the binary-classification head of a neural network: a model produces a raw score (a logit), and the sigmoid turns it into a probability. This calculator implements the standard definition from Goodfellow, Bengio & Courville's Deep Learning(MIT Press, 2016) and reproduces the behaviour of PyTorch's torch.sigmoid.
For an input x and an optional scale a (so z = a·x), the three modes are:
- Sigmoid.
σ(z) = 1 / (1 + e⁻ᶻ). To stop the exponential from overflowing on extreme inputs, the tool uses the algebraically identical sign-aware branch — 1/(1+e⁻ᶻ) when z ≥ 0 and eᶻ/(1+eᶻ) when z < 0 — the same trick asscipy.special.expit. The exponent stays ≤ 0, so nothing overflows and the result is never NaN. - Derivative.
σ′(z) = σ(z)·(1 − σ(z)). Computed from the already-stable σ(z). It reaches its maximum of 0.25 at z = 0 and approaches 0 as the sigmoid saturates — the gradient used in back-propagation (Deep Learning §6.2.2). - Inverse (logit).
logit(p) = ln(p / (1 − p))for a probability p in (0, 1). It maps a probability back to the raw score that produces it. The domain is enforced — p at exactly 0 or 1 is rejected, since the logit there is ∓∞.
To prove correctness the module computes σ(z) twice by independent formulas — the stable branch above and the tanh identity σ(z) = ½(1 + tanh(z/2)) — and reports the largest gap between them, which reads as 0 (or ~1e-16) for every input. All arithmetic is double-precision JavaScript Math.exp / Math.log; results are rounded only for display, never for chained computation, and nothing is sent to a server.
Four properties explain almost everything you see in the results table:
- Bounded and monotonic. σ is strictly increasing, so a larger score always maps to a larger probability and the output never leaves (0, 1). Order is preserved — ranking a set of items by raw score and ranking them by σ(score) produce the same list, which is why a threshold on the probability is the same thing as a threshold on the score.
- Symmetric about (0, 0.5). σ(−x) = 1 − σ(x). The probability of the negative class is just the sigmoid of the negated score, which is why a binary classifier needs only one output unit instead of two.
- Gradient capped at 0.25. σ′ peaks at 0.25 when x = 0 and decays quickly: at x = 6 it is already 0.002467, about 101× smaller. Chain ten such factors through a deep stack and the gradient is on the order of 1e-6 — the vanishing-gradient behaviour that moved hidden layers to ReLU and left sigmoid on output and gate units.
- Log-odds interpretation. The input is the natural log of the odds. Adding 1 to the score multiplies the odds by e ≈ 2.71828: a score of 0 is even odds (p = 0.5), a score of 1 is odds of 2.718 to 1 (p = 0.731059), and a score of 2 is 7.389 to 1 (p = 0.880797). Inverse mode runs that reading backwards.
The score itself usually comes from a linear model: in logistic regression it is w·x + b, and in a neural network it is the single output unit of the last layer. The scale factor a in this tool stands in for that weight, so σ(a·x) is exactly what one weighted feature would produce. When the classes are mutually exclusive rather than binary, the same idea generalises to the softmax calculator, and the loss you would then minimise is worked through step by step in the cross-entropy loss calculator.
Edge cases and floating-point limits
Every mode has a domain, and this tool enforces it instead of handing back a silent NaN or an Infinity. These are the cases worth knowing before you trust a printed number:
- Saturation in double precision. Once z reaches about 37, e⁻ᶻ drops below the spacing between doubles near 1 (2⁻⁵³ ≈ 1.1e-16), so 1 + e⁻ᶻ rounds to exactly 1 and σ(z) returns exactly 1.000000. In the other direction the exponential underflows and σ(z) returns exactly 0 near z = −745. Those are limits of 64-bit arithmetic, not errors. On GPUs, where 32-bit floats are the norm, saturation arrives far sooner — around |z| = 17.
- Why saturation matters downstream. When σ returns exactly 1, the log-loss term ln(1 − σ) is −∞. That is the reason deep-learning frameworks fuse the two operations into one numerically-stable op (PyTorch calls it
BCEWithLogitsLoss) rather than applying a sigmoid and then a log. This calculator shows the probability itself, so saturation is visible rather than hidden. - Inverse-mode boundaries.The logit is defined only for 0 < p < 1, so p = 0 and p = 1 are rejected with a message rather than returning ∓∞. p = 0.5 gives logit 0, and the function is antisymmetric: logit(0.2) = −logit(0.8) = −1.386294.
- A scale of zero. Setting a = 0 would collapse every input to σ(0) = 0.5, which is never what anyone wants, so the tool falls back to a = 1. Negative scales are allowed and simply mirror the curve, since σ(−a·x) = 1 − σ(a·x).
- Input parsing. Up to 200 values per run, separated by commas, spaces, tabs or new lines — a pasted
[-2, -1, 0]works as-is. A token that is not a number is named in the error instead of being quietly dropped, so a stray character never turns into a wrong answer.
Where the sigmoid is actually used
The formula is small, but it turns up in four distinct roles, roughly in the order you are likely to meet them:
- Logistic regression. The model fits weights on a linear score and passes it through σ to get a probability. Because the score is log-odds, each fitted coefficient has a direct reading: a coefficient of 0.7 means one extra unit of that feature multiplies the odds by e⁰·⁷ ≈ 2.01.
- Binary and multi-label output heads.One sigmoid unit answers a yes/no question. For multi-label problems — a photo that is both “beach” and “sunset” — each label gets its own independent sigmoid, and the probabilities are not required to sum to 1. That independence is the practical difference from softmax.
- Gates in gated networks.The forget, input and update gates of LSTM and GRU cells are sigmoids, because a value in (0, 1) reads naturally as “what fraction of this signal do I keep”. Multiplying by a gate output is a soft, differentiable switch.
- Calibration and scoring. Platt scaling fits a one-parameter sigmoid over an uncalibrated model score so the output can be read as a probability. Once you have those probabilities you still have to choose a cut-off, and that choice is best made from the ranking and threshold metrics in the ROC AUC calculator and the F1 score calculator.
One place the sigmoid is not the right tool: sampling temperature. A temperature setting reshapes a whole distribution over tokens, which is a softmax operation, not a scalar squash — the temperature and top-p visualizer covers that case. The scale factor here plays a similar sharpening role, but on a single value rather than across competing options.
Worked examples
Frequently asked questions
Sources & references
- PyTorch documentation — torch.nn.Sigmoid / torch.sigmoid (σ(x) = 1/(1+exp(−x)))
- SciPy documentation — scipy.special.expit (logistic sigmoid) and logit (its inverse)
- Goodfellow, Bengio & Courville — Deep Learning (MIT Press, 2016), §3.10 & §6.2.2
The formulas on this page were last cross-checked against these sources and PyTorch on 2026-08-27. The sigmoid is a stable mathematical definition, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.