Sigmoid function

Also known as: logistic function · sigmoid activation

On this page 7

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 xOutput σ(x)Gradient σ′(x)Regime
−6About 0.0025About 0.0025Saturated low
−2About 0.12About 0.105Transitional
00.50.25Most sensitive
2About 0.88About 0.105Transitional
6About 0.9975About 0.0025Saturated high
Sigmoid output and gradient at selected inputs

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.

RoleLocationWhy the sigmoid fits
Binary outputFinal layer of a classifierOutput reads as a probability
Multi-label outputOne unit per independent labelLabels need not sum to 1
GatingLSTM and GRU gates, gated linear unitsValues in 0 to 1 act as soft switches
Attention and routing weightsSome mixture-of-experts routersIndependent scores per expert
Hidden activationEarly multilayer perceptronsSmooth and bounded, now largely replaced
Where the sigmoid appears and why

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.

FunctionOutput rangeZero-centeredMain weakness
Sigmoid0 to 1NoSaturation and vanishing gradients
Tanh−1 to 1YesSaturation, though milder in practice
ReLU0 to infinityNoDead units for negative inputs
Swish or SiLUAbout −0.28 to infinityApproximatelySlightly higher compute cost
Softmax0 to 1, summing to 1Not applicableOnly for mutually exclusive classes
Sigmoid and related activation functions

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.

MistakeConsequenceFix
Sigmoid in deep hidden layersSlow or stalled trainingUse ReLU, GELU or Swish
Separate sigmoid and log lossOverflow and NaN values for large logitsUse a combined loss with logits
Sigmoid for exclusive classesProbabilities do not sum to 1Use softmax instead
Fixed 0.5 thresholdPoor results on imbalanced dataTune the threshold on validation data
Reading outputs as calibratedOverconfident probabilitiesApply temperature or Platt scaling
Common sigmoid mistakes and fixes

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.