Activation Functions in Neural Networks: Why Non-Linearity Matters

12 minute read

Published:

TL;DR: A neural network without activation functions is just a stack of linear layers pretending to be deep. Activation functions are what bend the geometry, control gradient flow, and decide whether a network behaves like a hard switch, a soft gate, or a smooth feature extractor.

Why Activation Functions Exist

Intuition First: Imagine stacking transparent overlays on a map. Each overlay is a straight line drawn across the city โ€” no matter how many you stack, you can only ever describe things that fit straight-line logic. Activation functions are what let each layer bend its overlay into a curve. Without them, ten layers of computation are exactly equivalent to one.

The core equation of a hidden layer is simple:

\[ h = \sigma(Wx + b) \]

The matrix multiplication Wx + b is only an affine transformation. If every layer did only that, then stacking ten layers would still collapse into one big affine transformation. Depth would give you more parameters, but not more expressive shape.

Activation functions are the thing that breaks that collapse. They inject non-linearity, which means the network can carve curved decision boundaries, represent thresholds, and model interactions that a linear model cannot.

Key Insight: an activation function decides how much of a neuron's signal should move forward. Some behave like hard on/off switches. Others behave like soft gates. Others are chosen mainly because they make gradients easier to optimize.
Linear only (no activation) Cannot separate โœ— With activation (non-linear) Clean separation โœ“
Animated โ€” Without activations, a deep network can only ever draw a straight line as its decision boundary (left). With non-linearity, it can learn the curved boundary that actually separates the data (right).

The Core Intuition

Think of a neuron as a tiny processor that first computes a score and then asks: should I pass this signal, suppress it, clip it, smooth it, or gate it?

  • A step activation behaves like a binary rule.
  • A sigmoid behaves like a soft probability gate.
  • A tanh behaves like a centered soft gate.
  • A ReLU behaves like a one-way valve: block negatives, pass positives.

That tiny local choice changes the global behavior of the whole network.

Step Sigmoid Tanh ReLU
The four classical activation shapes trace in sequence. Notice how the Step is a hard binary flip, Sigmoid and Tanh are smooth S-curves (but flatten in the tails), and ReLU is simply a half-rectification โ€” zero on the left, identity on the right.
Diagram showing a neuron computing a linear score and then passing it through different kinds of activation gates
Figure 1 โ€” The same linear score can be turned into very different behaviors depending on the activation: a hard threshold, a soft probability gate, or a one-way valve like ReLU. The activation is what decides how the raw score becomes a useful signal.

Historical Progression

How the field evolved

  1. Step / threshold activations: good for early perceptrons, but not differentiable enough for modern gradient-based learning.
  2. Sigmoid and tanh: smooth and differentiable, which made backpropagation practical, but they saturate.
  3. ReLU: dramatically simplified optimization and became the default for CNNs and MLPs.
  4. Modern smooth activations: GELU, SiLU, Swish, Mish, and gated variants improved optimization in large modern models.

Classical Families

A. Linear and Threshold Activations

These are conceptually important because they show the two extremes.

  • Linear / Identity: does nothing; useful mainly in regression outputs.
  • Step / Heaviside: flips from 0 to 1 once a threshold is crossed.

The linear activation is not wrong, but if you use it in every hidden layer, you lose the entire point of deep learning.

B. Squashing Functions

The first major family maps inputs into a bounded range:

  • Sigmoid: maps to [0, 1].
  • Tanh: maps to [-1, 1] and is zero-centered.
  • Softsign: also saturates, but more gently than tanh.
Sigmoid \[ \sigma(x) = \frac{1}{1 + e^{-x}} \]
Tanh \[ \tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}} \]
Softsign \[ \operatorname{softsign}(x) = \frac{x}{1 + |x|} \]

These functions were historically attractive because they are smooth and easy to differentiate. Their main weakness is saturation: for large positive or negative inputs, the derivative becomes tiny.

Key Insight: The sigmoid derivative peaks at exactly 0.25 when x=0. That means even at its best, it cuts the gradient in half compared to passing it unchanged. Stack 10 sigmoid layers and the best-case gradient shrinks to 0.25ยนโฐ โ‰ˆ 0.000001. That is the vanishing gradient problem in one number.

Concrete numerical example โ€” sigmoid saturation:

Input xฯƒ(x)ฯƒโ€ฒ(x) = ฯƒ(x)(1โˆ’ฯƒ(x))
00.5000.250 (maximum)
20.8800.105
40.9820.018
60.9980.002
80.99970.0002

Each row shows why neurons that receive large-magnitude inputs essentially stop learning โ€” the gradient through them is nearly zero.

C. Piecewise-Linear Functions

Then came the ReLU era:

  • ReLU: keeps the positive branch and zeros out the negative one.
  • Leaky ReLU: small negative slope instead of a hard zero
  • PReLU: learns that negative slope
  • RReLU: uses a random negative slope during training
  • ReLU6: same idea as ReLU, but clipped at 6
  • Thresholded ReLU: stays at zero until a chosen threshold
ReLU \[ \operatorname{ReLU}(x) = \max(0, x) \]
Leaky ReLU \[ \operatorname{LeakyReLU}(x) = \begin{cases} x, & x > 0 \\ \alpha x, & x \le 0 \end{cases} \]
ReLU6 \[ \operatorname{ReLU6}(x) = \min(\max(0, x), 6) \]

These functions made optimization much easier because their positive branch keeps a strong gradient.

Concrete step-by-step: how ReLU saves the gradient

Imagine a single neuron receives pre-activation z = 1.5 and the upstream gradient (from the loss) is ฮด = 0.8.

ActivationOutputLocal derivativeGradient passed back
Sigmoidฯƒ(1.5) = 0.818ฯƒโ€ฒ(1.5) = 0.1490.8 ร— 0.149 = 0.119
Tanhtanh(1.5) = 0.9051โˆ’0.905ยฒ = 0.1810.8 ร— 0.181 = 0.145
ReLUmax(0,1.5) = 1.510.8 ร— 1.0 = 0.800

ReLU passes the gradient through unchanged on the positive side. Stacked over many layers, that difference becomes enormous.

Grid of classical activation functions including linear, step, sigmoid, tanh, ReLU, Leaky ReLU, PReLU, RReLU, Softplus, Softsign, ReLU6, and Thresholded ReLU
Figure 2 โ€” A visual cheat sheet for the classical activation family. The main story is already visible in the shapes: squashing activations saturate, ReLU-like activations keep a strong positive branch, and clipped variants trade expressivity for stability or efficiency.

What the Shapes Are Telling You

You can often predict training behavior by looking at the curve.

Shape patternWhat it usually implies
Flat tailsRisk of vanishing gradients
Hard zero regionRisk of dead neurons
Smooth transitionMore stable optimization
Unbounded positive branchStrong gradient flow for active units
ClippingBetter control, but less expressivity

So activation functions are not just output transformations. They are also gradient transformations.

Gradient Perspective

Intuition First: Backpropagation is just the chain rule applied repeatedly. Each activation function contributes a multiplier to the chain. If those multipliers are consistently less than 1, the product shrinks toward zero as it travels backward โ€” that is vanishing gradients. If they are consistently greater than 1, the product explodes. The ideal multiplier is 1 on the active side, which is exactly what ReLU achieves.

Backpropagation trains a network by multiplying many derivatives together. That is where activation choice becomes decisive.

The four recurring problems

ProblemMeaning
Vanishing gradientsDerivatives become so small that early layers barely learn.
Exploding gradientsDerivatives become too large and make optimization unstable.
Dead neuronsSome ReLU units stay permanently inactive because they only see negative inputs.
SaturationSigmoid/tanh flatten for large magnitudes, so gradient flow collapses.

This is why ReLU became such a turning point: it did not solve everything, but it avoided the worst saturation behavior that slowed down older deep networks.

1. Active neuron z=1.2 gradient flows freely 2. Large negative update z=โˆ’0.4 output clipped to 0 by ReLU 3. Dead neuron output = 0, gradient = 0 weights never update again
Animated dead neuron lifecycle. A neuron receiving a large negative weight update flips to z < 0. ReLU clips its output to zero, so no gradient flows back (โˆ‚ReLU/โˆ‚z = 0 for z < 0). The weights are now frozen permanently โ€” the neuron is dead.
Diagram contrasting vanishing gradients, dead neurons, and healthy gradient flow across common activations
Figure 3 โ€” Activation choice is really a gradient-management decision. Sigmoid and tanh can flatten into tiny derivatives, ReLU can kill units on the negative side, and smoother modern activations try to preserve useful gradient flow near zero.

Practical First Recommendations

If you are just starting, a strong first mental map is:

Use caseGood default
Hidden layers in MLPs / CNNsReLU or Leaky ReLU
Very deep modern architecturesGELU or SiLU
Binary outputSigmoid
Multi-class outputSoftmax
Regression outputLinear

The later chapters in this mini-series cover the smoother modern functions and the output-layer functions in more detail.

What Can Go Wrong with Classical Activations?

Typical failure modes

ActivationPotential problem
StepNot useful for standard backpropagation because the derivative is zero almost everywhere.
SigmoidSaturates in the tails and causes vanishing gradients in deep hidden stacks.
TanhZero-centered, but still saturates for large magnitudes.
ReLUCan create dead neurons that never reactivate.
ReLU6 / clipped variantsGain control, but can reduce expressivity if clipping is too aggressive.

Side-by-Side Comparison: Classical Activations

<div class=โ€act-svg-wrapโ€>

<svg xmlns=โ€http://www.w3.org/2000/svgโ€ viewBox=โ€0 0 580 220โ€ style=โ€max-width:580px;width:100%โ€> <rect x=โ€5โ€ y=โ€5โ€ width=โ€178โ€ height=โ€210โ€ rx=โ€9โ€ fill=โ€#f0f9ffโ€ stroke=โ€#bae6fdโ€/> <text x=โ€94โ€ y=โ€21โ€ text-anchor=โ€middleโ€ class=โ€panel-lblโ€ fill=โ€#0c4a6eโ€>Sigmoid</text> <line x1=โ€15โ€ y1=โ€110โ€ x2=โ€178โ€ y2=โ€110โ€ class=โ€panel-axโ€/> <line x1=โ€94โ€ y1=โ€30โ€ x2=โ€94โ€ y2=โ€200โ€ class=โ€panel-axโ€/> <path d=โ€M18,185 C30,183 42,178 55,165 S78,130 94,110 S115,70 130,52 S158,35 180,33โ€ class=โ€curve-fn c-sig-fnโ€/> <path d=โ€M18,185 C30,184 45,180 60,170 S80,148 94,140 S112,148 128,170 S152,183 180,185โ€ class=โ€curve-fn c-sig-derโ€/> <line x1=โ€15โ€ y1=โ€197โ€ x2=โ€35โ€ y2=โ€197โ€ stroke=โ€#0891b2โ€ stroke-width=โ€2โ€/> <text x=โ€38โ€ y=โ€200โ€ class=โ€leg-txtโ€ fill=โ€#0891b2โ€>f(x)</text> <line x1=โ€70โ€ y1=โ€197โ€ x2=โ€90โ€ y2=โ€197โ€ stroke=โ€#7dd3e8โ€ stroke-width=โ€2โ€/> <text x=โ€93โ€ y=โ€200โ€ class=โ€leg-txtโ€ fill=โ€#7dd3e8โ€>fโ€ฒ(x)</text> <text x=โ€94โ€ y=โ€211โ€ text-anchor=โ€middleโ€ font-family=โ€sans-serifโ€ font-size=โ€8.5โ€ fill=โ€#ef4444โ€>max fโ€ฒ=0.25 โ€” saturates!</text> <rect x=โ€200โ€ y=โ€5โ€ width=โ€178โ€ height=โ€210โ€ rx=โ€9โ€ fill=โ€#fff7edโ€ stroke=โ€#fed7aaโ€/> <text x=โ€289โ€ y=โ€21โ€ text-anchor=โ€middleโ€ class=โ€panel-lblโ€ fill=โ€#7c2d12โ€>Tanh</text> <line x1=โ€210โ€ y1=โ€110โ€ x2=โ€373โ€ y2=โ€110โ€ class=โ€panel-axโ€/> <line x1=โ€289โ€ y1=โ€30โ€ x2=โ€289โ€ y2=โ€200โ€ class=โ€panel-axโ€/> <path d=โ€M213,185 C225,183 238,175 252,160 S275,120 289,110 S308,85 320,60 S350,37 372,34โ€ class=โ€curve-fn c-tan-fnโ€/> <path d=โ€M213,185 C228,183 245,175 260,162 S279,135 289,110 S302,76 315,60 S348,50 372,50โ€ class=โ€curve-fn c-tan-derโ€/> <line x1=โ€210โ€ y1=โ€197โ€ x2=โ€230โ€ y2=โ€197โ€ stroke=โ€#f97316โ€ stroke-width=โ€2โ€/> <text x=โ€233โ€ y=โ€200โ€ class=โ€leg-txtโ€ fill=โ€#f97316โ€>f(x)</text> <line x1=โ€265โ€ y1=โ€197โ€ x2=โ€285โ€ y2=โ€197โ€ stroke=โ€#fbbf80โ€ stroke-width=โ€2โ€/> <text x=โ€288โ€ y=โ€200โ€ class=โ€leg-txtโ€ fill=โ€#fbbf80โ€>fโ€ฒ(x)</text> <text x=โ€289โ€ y=โ€211โ€ text-anchor=โ€middleโ€ font-family=โ€sans-serifโ€ font-size=โ€8.5โ€ fill=โ€#f97316โ€>zero-centered, still saturates</text> <rect x=โ€395โ€ y=โ€5โ€ width=โ€178โ€ height=โ€210โ€ rx=โ€9โ€ fill=โ€#f0fdf4โ€ stroke=โ€#bbf7d0โ€/> <text x=โ€484โ€ y=โ€21โ€ text-anchor=โ€middleโ€ class=โ€panel-lblโ€ fill=โ€#14532dโ€>ReLU</text> <line x1=โ€405โ€ y1=โ€110โ€ x2=โ€568โ€ y2=โ€110โ€ class=โ€panel-axโ€/> <line x1=โ€484โ€ y1=โ€30โ€ x2=โ€484โ€ y2=โ€200โ€ class=โ€panel-axโ€/> <path d=โ€M408,110 H484 L568,30โ€ class=โ€curve-fn c-rel-fnโ€/> <path d=โ€M408,110 H484 L568,110โ€ class=โ€curve-fn c-rel-derโ€/> <line x1=โ€405โ€ y1=โ€197โ€ x2=โ€425โ€ y2=โ€197โ€ stroke=โ€#16a34aโ€ stroke-width=โ€2โ€/> <text x=โ€428โ€ y=โ€200โ€ class=โ€leg-txtโ€ fill=โ€#16a34aโ€>f(x)</text> <line x1=โ€460โ€ y1=โ€197โ€ x2=โ€480โ€ y2=โ€197โ€ stroke=โ€#86efacโ€ stroke-width=โ€2โ€/> <text x=โ€483โ€ y=โ€200โ€ class=โ€leg-txtโ€ fill=โ€#86efacโ€>fโ€ฒ(x)</text> <text x=โ€484โ€ y=โ€211โ€ text-anchor=โ€middleโ€ font-family=โ€sans-serifโ€ font-size=โ€8.5โ€ fill=โ€#16a34aโ€>fโ€ฒ=1 always (positive side)</text> </svg>
Each panel shows the function (solid) and its derivative (dashed/lighter). Sigmoid and Tanh derivatives flatten to near-zero in the tails โ€” vanishing gradient territory. ReLU's derivative is exactly 1 on the positive side, so gradients pass through undistorted for active neurons.

</div>

Common Mistakes

  1. Thinking depth alone creates expressivity. Without non-linearity, depth collapses into one linear map.
  2. Using sigmoid everywhere. It is useful at the output for binary probabilities, but usually a weak default for deep hidden stacks.
  3. Thinking ReLU is โ€œjust a formula.โ€ It changed deep learning because of its gradient behavior, not only because it is simple.

Main Takeaway

Activation functions determine what kind of signal a neuron emits and how gradients travel backward through the network. That is why they sit at the intersection of expressivity, optimization, and practical performance.

The clean historical story is: step โ†’ sigmoid/tanh โ†’ ReLU โ†’ modern smooth and gated activations.

References

  1. Nair, V. and Hinton, G. E. โ€œRectified Linear Units Improve Restricted Boltzmann Machines.โ€ ICML 2010.
  2. Goodfellow, I., Bengio, Y., and Courville, A. Deep Learning. MIT Press, 2016.
  3. Glorot, X., Bordes, A., and Bengio, Y. โ€œDeep Sparse Rectifier Neural Networks.โ€ AISTATS 2011.