Activation functions are the small non-linear functions applied at every neuron that give neural networks their power to learn curves, images and language. Choosing the right activation function for each layer — ReLU, sigmoid, softmax, tanh, GELU and more — is one of the most practical decisions in deep learning. This complete guide compares all the main activation functions and gives you a simple rule for choosing.

See them together
Three of the most common activation functions overlaid: ReLU (blue), sigmoid (purple) and tanh (green). Notice how ReLU grows without bound while sigmoid and tanh saturate.
Why activation functions matter
Every neuron computes a weighted sum of its inputs, which is linear. Stack a hundred linear layers and you still have a linear function. Activation functions are the non-linear step applied after that sum; they are what let neural networks approximate curves, images, language and any other complex pattern. Choosing the right one for each layer is one of the most practical decisions in deep learning.
The main activation functions at a glance
| Function | Range | Best for |
|---|---|---|
| ReLU | [0, ∞) | Hidden layers (default) |
| Leaky ReLU | (−∞, ∞) | Fixing dead neurons |
| ELU | (−α, ∞) | Zero-centred hidden layers |
| GELU | (−0.17, ∞) | Transformers |
| Swish | (−0.28, ∞) | Deep / mobile nets |
| Tanh | (−1, 1) | RNN gates |
| Sigmoid | (0, 1) | Binary output |
| Softmax | (0, 1), sums to 1 | Multi-class output |
How to choose an activation function
The problem good activation functions solve
The older activation functions — sigmoid and tanh — saturate, causing the vanishing gradient problem that once made deep networks untrainable. The modern ReLU family keeps gradients strong, which is why almost every activation function you will reach for in a hidden layer today is a ReLU variant. Read each linked guide for the formula, an interactive plot, and Python code.
Activation functions in Python (Keras)
from tensorflow.keras.layers import Dense
Dense(128, activation="relu") # hidden layer
Dense(1, activation="sigmoid") # binary output
Dense(10, activation="softmax") # 10-class outputWhy non-linearity is non-negotiable
It is worth seeing exactly why a network needs these non-linear steps at all, because the argument is short and convincing. Stack two linear layers and the result is still linear: multiplying by one matrix and then another is the same as multiplying by a single combined matrix, so a hundred stacked linear layers collapse into one. A model like that can only draw straight-line decision boundaries and fit straight-line relationships, no matter how many layers or neurons you give it. The non-linear step inserted after each layer breaks that collapse, letting each layer bend and fold the space so the next layer sees a richer, reshaped version of the data. That folding, repeated across many layers, is what lets deep networks carve out the wildly complicated boundaries needed to separate cats from dogs or spam from mail. Remove it and the deepest network in the world becomes a glorified linear regression.
How the choice affects training speed
Beyond simply enabling learning, the choice quietly governs how fast a network learns. The saturating curves of the early era flatten at their extremes, so a neuron pushed into that flat region receives almost no gradient and effectively stops updating. The modern rectified family keeps a healthy gradient across its active range, which is the single biggest reason deep networks that once took weeks now train in hours. The shape also interacts with weight initialisation and normalisation: schemes like He and Xavier were derived specifically to keep the signal at a sensible scale as it passes through a particular non-linearity, and batch or layer normalisation exists partly to keep neurons out of their dead zones. In practice this means the choice is not an isolated decision but part of a package with initialisation and normalisation, and changing one often means revisiting the others.
Reading a network’s health through its units
A surprisingly useful debugging habit is to watch the distribution of neuron outputs during the first few epochs. If a large fraction sit pinned at zero or jammed against a saturating ceiling, the network is wasting capacity and often barely learning, and the fix is usually smaller initial weights, a lower learning rate, or a normalisation layer rather than a fancier design. Healthy units show a spread of values that shifts sensibly as training proceeds. This kind of diagnosis turns an abstract choice into something concrete you can measure, and it is far more productive than blindly swapping one curve for another and hoping the metrics improve.
A short history
The story runs from the smooth, biologically-inspired curves of the 1980s, through the long winter when deep networks were considered nearly untrainable, to the 2012 breakthrough when a simple rectifier helped a deep convolutional network win a major image contest by a wide margin and reignited the whole field. Since then the trend has been toward smooth, self-gating variants that squeeze out a little extra accuracy on very large models, while the plain rectifier remains the dependable default everywhere else. Knowing this arc helps you read papers and codebases: an older model will lean on the saturating curves, a modern transformer will use a smooth gate, and the reasoning behind each choice traces directly back to the training-speed and gradient-flow ideas above.
Beginner questions worth settling early
A few questions come up again and again, and settling them early saves confusion. Does every layer need the same non-linearity? No — the hidden layers usually share one for consistency, but the output layer follows a completely different rule dictated by the task, so a network commonly uses a rectifier throughout its body and a sigmoid or normalised exponential at the very end. Can you skip the non-linearity on just one hidden layer to save compute? You can, but that layer then merges mathematically with its neighbour and adds no representational power, so it is almost always wasted. Do these functions have learnable parameters? Most do not — they are fixed shapes — though a handful, such as the parametric rectifier, learn a small slope during training. Should you invent your own? Rarely worth it; the standard handful were found after extensive search and cover almost every need, and a custom shape has to clear a high bar to beat them. Finally, do they differ between frameworks? The definitions are identical across libraries, so a model’s behaviour transfers even when the exact function names do not. Keeping these answers in mind lets you make the choice quickly and correctly, and it stops the topic from feeling more mysterious than it really is once the handful of core ideas click into place.
The bottom line
If you take away one principle, let it be this: use a rectifier in the hidden layers by default, pick the output non-linearity from the task rather than from habit, and only reach for a smooth or exotic variant once a working baseline tells you it is worth the cost. That single rule handles the overwhelming majority of models you will ever build, and the linked guides fill in the formula, an interactive plot, and code for each choice whenever you need the detail.
A quick rule of thumb
When you are unsure, start simple and only add complexity if the metrics ask for it: a rectified linear unit in every hidden layer, the correct output for your task, and nothing fancier until you have a working baseline. Smooth, modern variants earn their keep on very large models; on small and medium networks they rarely move the needle enough to justify the extra compute and engineering. It also pays to keep the choice consistent within a network rather than mixing many different curves, because each one shifts the distribution of values the next layer sees. Finally, remember that the output layer follows a different rule from the hidden layers — it is dictated by the task, not by training speed. For the mathematical background and a broader catalogue, the Wikipedia activation function article is a solid reference.
Explore each activation function
- ReLU — the fast default for hidden layers.
- Leaky ReLU — fixes dying ReLU.
- ELU — smooth negatives, zero-centred.
- GELU — powers transformers.
- Swish — smooth and self-gated.
- Tanh — zero-centred, for RNNs.
- Sigmoid — binary output.
- Softmax — multi-class output.
- Sigmoid vs Softmax — which output to use.
- Vanishing Gradient Problem — what they must avoid.