If you put in an x value of 5, the sigmoid will give you 0.9933, but if you put in -5 for x, the output will be 0.0067. Those teeny-tiny differences between 0 and 1 on each side are why your neural network may not learn anything halfway through training, but no one ever tells you that when they explain the equation.
Sigmoid is the classic activation function from machine learning days of old and even in 2026, it is being used in places that no one expects. This guide will explain what the equation is, the derivative of that equation, its limitations, and the places where it’s used.
What Will I Learn?
What Is the Sigmoid Function?
Sigmoid is a math function that squashes any real number — positive, negative, huge, tiny — into a value between 0 and 1. The formula:
Here, x is any value input, and e is Euler’s number, equal to about 2.718. Sigmoid takes a really big positive value and slowly approaches 1. Sigmoid takes a really negative value and slowly approaches 0. Sigmoid takes a value of 0 and gives out 0.5 — this is the midpoint of the function.
Think of the result as an elongated “S” laid on its side. Flat on both sides and very steep in the middle. The part which is steep is the only place where sigmoid makes sense, while the flat parts will create problems for us, as you will soon see.
Since the result is between 0 and 1, it can be treated as a probability. An algorithm asking “is this email spam?” would give a result of 0.92 in its last sigmoidal layer — this would mean 92% chance the email is spam, but not 100%.
Sigmoid vs. Logistic Function — Are They the Same?
Mostly, yes. Strictly speaking, sigmoid functions are any S-shaped curves; there are many different variations. However, the specific formula listed above, 1/(1+e^-x), is a logistic function, and is so widely-used in machine learning that “sigmoid” is synonymous with “logistic function.”
Logistic functions are not a product of computer science. The logistic function was introduced by Belgian mathematician Pierre François Verhulst in the 1830s in order to describe the growth of populations in which the rate of increase decreased as the population approached a certain level— such as the bacteria population in a petri dish that started off increasing rapidly but slowed down after running out of food. It took over a hundred and fifty years for the same mathematical model to prove its utility for artificial neural networks.
Properties of the Sigmoid Function
There are four mathematical characteristics of sigmoid which are all important for practical reasons.
Domain. You may give sigmoid ANY real value, there is no input that it will not process. Try doing this with a square root function – and it won’t work.
Range. The output always lies between 0 and 1; more precisely, it never equals either 0 or 1, but is strictly between them. This is why sigmoid can be used for probabilistic-like outputs, which do not reach 100% certainty.
Monotonicity. An increase in input results in an increase in output without exception. Therefore, higher weighted sums correspond to higher confidence levels.
Differentiability. Sigmoid is infinitely differentiable everywhere, there are no discontinuities or sharp turns. It is essential because neural networks training relies on finding the derivative of a function.
Sigmoid Function Formula and Derivative
Step-by-Step Derivative Derivation
Here’s the part most explainers either skip or rush through. Let’s actually do it.
Start with the function: y = σ(x) = 1/(1 + e^-x). Let u = 1 + e^-x, so y = 1/u.
Differentiating u with respect to x gives du/dx = -e^-x.
Differentiating y with respect to u gives dy/du = -1/u².
Apply the chain rule: dy/dx = (dy/du) × (du/dx) = (-1/u²) × (-e^-x) = e^-x / u².
Substitute u back in: dy/dx = e^-x / (1 + e^-x)².
Here’s the elegant part. Since σ(x) = 1/(1+e^-x), it follows that 1 – σ(x) = e^-x/(1+e^-x). Substitute that in, and the whole derivative collapses down to:
That’s an extraordinarily neat solution. Usually, to get the derivative, you need to calculate the function’s entire input again. However, for sigmoid’s function, the derivative can be calculated directly using the function output. It is that particular feature that used to make backpropagation easy computationally-wise in times when computing capacity was the real issue.
Worked Examples
σ'(0): σ(0) = 1/(1+e⁰) = 1/2. So σ'(0) = 0.5 × (1 – 0.5) = 0.25. This is the maximum possible value of sigmoid’s derivative — it never gets any steeper than this.
σ'(2): σ(2) ≈ 0.88. So σ'(2) ≈ 0.88 × 0.12 ≈ 0.1056.
σ'(-1): σ(-1) ≈ 0.2689. So σ'(-1) ≈ 0.2689 × 0.7311 ≈ 0.1966.
Why Sigmoid Causes the Vanishing Gradient Problem
Something should be noted about those three numbers. At x = 0, the derivative value reaches 0.25 – the maximum possible. At x = 2, the derivative is equal to 0.10, which is considerably lower. If you take x = 10, the derivative will be equal to 0.00004.
This is called vanishing gradient problem, and here is how it looks like when working in practice: you start training your network, and see very little loss after a few epochs. You start thinking that your learning rate is incorrect, and try to change it. Yet the real reason is often the values of weights in previous layers, which make the output fall into the area of the function that is almost linear with respect to the gradient.
If you have five or six sigmoid layers, you multiply five or six such numbers at the backpropagation stage. If you do 0.1 * 0.1 * 0.1 * 0.1 * 0.1 * 0.1, you will get 0.000001, which is practically equal to zero.
Sigmoid vs. Tanh vs. ReLU vs. Softmax
No single page puts all four side by side, which is strange given how often they come up together. Here’s the comparison:
| Function | Output Range | Zero-Centered? | Best For | Main Limitation |
| Sigmoid | 0 to 1 | No | Binary classification output layer | Vanishing gradient at extremes |
| Tanh | -1 to 1 | Yes | Hidden layers (better than sigmoid) | Still saturates at extremes |
| ReLU | 0 to ∞ | No | Hidden layers in deep networks | “Dying ReLU” — neurons can go permanently inactive |
| Softmax | 0 to 1 (sums to 1 across outputs) | No | Multi-class output layer | Only meaningful across multiple outputs, not single values |
It might be worthwhile mentioning a mistake that’s often made when it comes to the use of these two activation functions: softmax is not an alternative for sigmoid as opposed to ReLU. Softmax deals with the situation where the input instance is assigned to exactly one out of multiple categories. Sigmoid takes care of the situation where the input could be tagged with multiple labels simultaneously.
How to Implement Sigmoid in Python
NumPy Implementation
python
import numpy as np
def sigmoid(x):
return 1 / (1 + np.exp(-x))
print(sigmoid(0)) # 0.5
print(sigmoid(2)) # 0.8807970779778823
print(sigmoid(-2)) # 0.11920292202211755
That’s the textbook version, and it works fine for most values. It breaks for extreme inputs, though.
Avoiding Numerical Overflow
Try sigmoid(-1000) with the code above and NumPy throws an overflow warning — e^1000 is too large a number for a standard float to hold. The fix is to branch the calculation depending on whether x is positive or negative, so you never compute e raised to a huge positive power:
import numpy as np
def stable_sigmoid(x):
return np.where(
x >= 0,
1 / (1 + np.exp(-x)),
np.exp(x) / (1 + np.exp(x))
)
print(stable_sigmoid(-1000)) # 0.0 -- no warning, no crash
print(stable_sigmoid(1000)) # 1.0
Honestly, this is the kind of detail that separates code that works in a notebook from code that survives production. Most tutorials skip it entirely.
In PyTorch, you’d just call torch.sigmoid(x). In TensorFlow, tf.sigmoid(x). Both handle the overflow case internally, which is exactly why most production code uses the framework’s built-in version instead of writing sigmoid from scratch — you only really write it yourself to understand what’s happening under the hood.
Where Sigmoid Is Still Used in 2026
In my opinion, this is an incorrect paradigm of thinking. In most articles, the role of ReLU is presented as one which has replaced sigmoid. This is not quite true; it just switched places.
Sigmoid is not used as an activation function in hidden layers of a deep feedforward or convolutional neural network nowadays – this job is reserved almost exclusively for ReLU functions and their derivatives. However, sigmoid remains a standard function for:
- Output layers for binary classification tasks – when there is a need to have a 0-to-1 probability of something.
- LSTM and GRU cells’ gating mechanisms – when the function’s bounded output is used for controlling how much information is kept by the memory cell. This is probably one of the key applications of the function today – but it is seldom mentioned in basic tutorials.
- Attention mechanisms, in certain gating mechanism variants, when there is a need for a bounded weight that scales values smoothly.
Activation functions derived from the sigmoid function – such as SiLU function (which is also called Swish and is defined as the product of x and sigmoid(x)).
When Should You Use the Sigmoid Function?
Sigmoid is appropriate when:
- One output probability is required for binary classification.
- One is creating gates within an LSTM, GRU, or other recurrent neural network.
- The network in question is not sufficiently deep for the vanishing gradient problem to be a consideration.
Sigmoid should not be used when:
- A number of layers are being used and it is necessary for the gradient to propagate through all layers without obstruction.
- One is performing a multiclass classification problem (use softmax) or creating a very large and very deep architecture (ReLU and its variations are the default choice).
Frequently Asked Questions
Q1. What is the sigmoid function used for?
Ans. The sigmoid function maps any number onto the range [0, 1], making it suitable for output layers of classifiers with only two classes and as a gate for LSTM and GRU recurrent networks.
Q2. What is the derivative of the sigmoid function?
Ans. σ'(x) = σ(x) × (1 – σ(x)). It can be calculated directly from the function’s own output, without needing to recompute the original input.
Q3. Is sigmoid the same as logistic regression?
Ans. Not exactly. Logistic regression is an algorithm, while sigmoid is just the mathematical curve it uses to transform the sum of inputs into probability.
Q4. Why is sigmoid considered bad for deep neural networks?
Ans. Due to the fact that the derivative of the sigmoid function tends to zero at large values of its arguments. As one stacks sigmoid layers, their derivatives become smaller and smaller when multiplied in backpropagation.
Q5. What replaced sigmoid in modern hidden layers?
Ans. ReLU and all of its versions (Leaky ReLU, GELU, SiLU) have taken over from sigmoid for use in the majority of hidden layers due to their non-saturation with respect to positive values and low computational cost. However, sigmoid manages to retain its position in the output layer and gating process