The sigmoid function, also called the logistic function, is the S-shaped curve defined as σ(x) = 1 / (1 + e^(−x)), which maps any real input to an output strictly between 0 and 1. In neural networks, it is used as an activation function, as a gate that controls information flow, and as the output layer that turns a raw score into a probability for binary classification.
The sigmoid was the dominant activation in early multilayer perceptrons because it is smooth, differentiable and biologically suggestive of a neuron firing rate. Its tendency to saturate and cause vanishing gradients later pushed it out of hidden layers in deep networks, but it remains essential at the output and inside recurrent and gated architectures.
Mathematical definition and key properties
The sigmoid function takes a real number, often called a logit, and squashes it into the open interval from 0 to 1. At x = 0 the output is exactly 0.5, large positive inputs approach 1, and large negative inputs approach 0. The curve is point-symmetric around (0, 0.5), which gives the useful identity σ(−x) = 1 − σ(x).
Its derivative has an elegant closed form, σ′(x) = σ(x) · (1 − σ(x)), so the gradient can be computed directly from the forward output. The derivative reaches its maximum of 0.25 at x = 0 and decays quickly toward zero in both tails.
| Input x | Output σ(x) | Gradient σ′(x) | Regime |
|---|---|---|---|
| −6 | About 0.0025 | About 0.0025 | Saturated low |
| −2 | About 0.12 | About 0.105 | Transitional |
| 0 | 0.5 | 0.25 | Most sensitive |
| 2 | About 0.88 | About 0.105 | Transitional |
| 6 | About 0.9975 | About 0.0025 | Saturated high |
The inverse of the sigmoid is the logit function, log(p / (1 − p)), which converts a probability back into log-odds. This pairing is the reason the sigmoid appears naturally in logistic regression and in any model that predicts log-odds.
Roles of the sigmoid in neural networks
The sigmoid serves three distinct roles in modern neural networks, and the trade-offs differ for each. Confusing these roles is a common source of design errors.
| Role | Location | Why the sigmoid fits |
|---|---|---|
| Binary output | Final layer of a classifier | Output reads as a probability |
| Multi-label output | One unit per independent label | Labels need not sum to 1 |
| Gating | LSTM and GRU gates, gated linear units | Values in 0 to 1 act as soft switches |
| Attention and routing weights | Some mixture-of-experts routers | Independent scores per expert |
| Hidden activation | Early multilayer perceptrons | Smooth and bounded, now largely replaced |
In LSTM and gated recurrent units, sigmoid gates decide how much of the previous state to keep and how much new input to write. Because each gate value lies between 0 and 1, it acts as a differentiable switch that the network can learn to open or close.
The sigmoid also appears inside newer activations. Swish, also known as SiLU, is defined as x · σ(x), and SwiGLU uses the same product in a gated form. These functions keep the smooth gating behavior of the sigmoid while avoiding its saturation for positive inputs.
Sigmoid compared with other activation functions
Compared with modern alternatives, the sigmoid is bounded, smooth and non-zero-centered, which makes it a poor default for hidden layers. The table contrasts it with its closest neighbors.
| Function | Output range | Zero-centered | Main weakness |
|---|---|---|---|
| Sigmoid | 0 to 1 | No | Saturation and vanishing gradients |
| Tanh | −1 to 1 | Yes | Saturation, though milder in practice |
| ReLU | 0 to infinity | No | Dead units for negative inputs |
| Swish or SiLU | About −0.28 to infinity | Approximately | Slightly higher compute cost |
| Softmax | 0 to 1, summing to 1 | Not applicable | Only for mutually exclusive classes |
Tanh is a rescaled sigmoid, since tanh(x) = 2σ(2x) − 1, and its zero-centered output usually trains faster in hidden layers. Softmax generalizes the sigmoid to many classes: a two-class softmax is mathematically equivalent to a sigmoid applied to the difference of the two logits.
The vanishing gradient problem and saturation
The sigmoid’s largest practical drawback is that its gradient never exceeds 0.25. During backpropagation, gradients are multiplied layer by layer, so a stack of sigmoid layers can shrink the signal by a factor of four or more per layer, leaving early layers almost untrained.
Saturation makes the problem worse. When pre-activations drift far from zero, the output sticks near 0 or 1 and the gradient approaches zero, so the unit stops learning. Because outputs are always positive, the sigmoid also produces gradients of the same sign for all incoming weights, which leads to inefficient zigzag updates.
These effects were a major reason deep networks were hard to train before about 2010. ReLU activations, careful weight initialization, normalization layers and residual connections together solved most of the problem for hidden layers.
Practical guidance and common mistakes
In practice, the sigmoid should be used where a bounded probability or gate is genuinely needed, and numerical details deserve care. The table summarizes typical errors and their fixes.
| Mistake | Consequence | Fix |
|---|---|---|
| Sigmoid in deep hidden layers | Slow or stalled training | Use ReLU, GELU or Swish |
| Separate sigmoid and log loss | Overflow and NaN values for large logits | Use a combined loss with logits |
| Sigmoid for exclusive classes | Probabilities do not sum to 1 | Use softmax instead |
| Fixed 0.5 threshold | Poor results on imbalanced data | Tune the threshold on validation data |
| Reading outputs as calibrated | Overconfident probabilities | Apply temperature or Platt scaling |
Most frameworks provide a numerically stable binary cross-entropy with logits, which computes the sigmoid and the loss in one step using the log-sum-exp trick. Using it instead of a separate sigmoid layer avoids overflow for inputs beyond about ±40 in single precision.
Stripped to the essentials
The sigmoid function is a soft on-off switch. You give it any number. It returns a value between 0 and 1. Big positive numbers come out close to 1. Big negative numbers come out close to 0. Zero comes out as one half.
This makes it handy for saying how likely something is. The catch is that it barely reacts to very large or very small inputs, which can make deep networks learn slowly.
Where it is applied
An email provider trains a neural network to flag phishing messages. The network processes the sender, links and text of each message and produces a single raw score. A sigmoid output unit turns that score into a probability, for example 0.93 for a message that imitates a bank login page.
Because only about one message in a thousand is phishing, the team does not use the default 0.5 threshold. They tune the cutoff on validation data and choose 0.85 for automatic quarantine and 0.5 for a warning banner. The model is trained with a combined sigmoid and cross-entropy loss on logits to avoid numerical overflow.
The result is a filter that quarantines most phishing attempts while keeping false alarms on legitimate mail low, and the probability scores also let analysts review borderline cases first.