Formula Bro

Math and physics formulas, explained like you are new.


ReLU Activation

In one sentence: ReLU keeps positive numbers unchanged and replaces every negative number with zero, like a switch that is on when the input is positive and off otherwise.

ReLU(z)=max⁡(0,z)\text{ReLU}(z) = \max(0, z)

Read it out loud: “ReLU of z equals the larger of zero and z. ReLU is short for rectified linear unit. The letter z is the input number, which is usually a weighted sum plus a bias, and max means take the bigger of the two numbers.”

Before you start

The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.

Positive, negative and zero on the number line

Numbers to the right of zero on the number line are positive, and numbers to the left are negative. Zero sits between them and is neither. A negative number is a value below zero, such as a temperature of minus 5 degrees Celsius. Multiplying two negative numbers gives a positive number, and adding a negative number is the same as subtracting its size.

The maximum max⁡(a,b)\max(a, b)

max⁡(a,b)\max(a, b) means ‘the bigger of the two numbers aa and bb’. So max⁡(0,4)=4\max(0, 4) = 4, because 4 is bigger than 0, and max⁡(0,−3)=0\max(0, -3) = 0, because 0 is bigger than −3-3. The notation picks one of the two numbers and throws the other away, which is exactly what the ReLU rule does to a negative input.

An activation function

An activation function is a rule that a neuron applies to its total before passing the result on. It decides how strong the output is. Without a rule like this, a stack of neuron layers would combine into one straight-line formula. The activation function adds a bend, which is what lets the network represent curved patterns.

Straight lines, slope and linear

A straight line has a constant slope, the amount it rises for each step to the right. The line y=zy = z has slope 1, because each step to the right rises by one step up. A rule is called linear when it is a straight line in this sense. ReLU is not linear overall, because it is a straight line with slope 1 on the positive side and a flat line at 0 on the negative side, which makes a bend.

Gradient, the slope used for learning

The gradient of a function is how much its output changes when its input changes a tiny bit. During training, gradients tell the network which way to adjust its weights. For ReLU, the gradient is 1 on the positive side, because the output follows the input, and 0 on the negative side, because the output stays fixed at zero no matter how the input moves.

What each symbol means

SymbolMeaning

ReLU(z)\text{ReLU}(z)

The rectified linear unit output: the value the neuron passes on to the next layer. It is never negative, because negative inputs become 0. It has no unit in most networks, and it is a plain number like the input.

zz

The input to the activation, usually the weighted sum of a neuron’s inputs plus its bias. It can be any real number, positive, negative or zero. In the example it is a made-up score that says how much the fan should run, and it has no unit.

max⁡(0,z)\max(0, z)

The larger of the two numbers 0 and zz. If zz is positive, the result is zz itself, passed on unchanged. If zz is negative, the result is 0. This is the entire rule, written as one comparison.

The formula piece by piece

z=w1x1+w2x2+bz = w_1 x_1 + w_2 x_2 + b

Start with the neuron’s weighted sum. Each input is multiplied by its weight, the products are added, and the bias is added last. This total zz is the number ReLU will read, and it can be positive or negative depending on the inputs.

max⁡(0,z)\max(0, z)

Compare the total with 0 and keep the bigger one. A positive total is kept exactly as it is. A negative total loses the comparison and becomes 0, so the neuron outputs nothing for that input.

ReLU(z)=max⁡(0,z)\text{ReLU}(z) = \max(0, z)

The whole formula in one sentence: the ReLU output of zz equals the larger of zero and zz, so positive values pass through unchanged and negative values become zero.

What the formula is doing, and why

An activation function sits at the output of a neuron and decides what gets passed on. A neuron first computes a weighted sum zz of its inputs, then applies the activation. Without a non-linear activation, a stack of layers collapses into one big linear formula, and that formula cannot learn curved patterns.

What does ReLU do? ReLU, short for rectified linear unit, is the simplest useful choice, and it has two cases. If zz is positive, the output equals zz, a straight line with slope 1. If zz is zero or negative, the output is 0. The output never goes below zero. The bend at zero is the only non-straight part, and that bend is enough to let stacked layers learn curved patterns.

Why is it popular? The main advantage is cheap computation. Producing the output takes one comparison, with no exponentials. For positive inputs the slope is always 1, so the learning signal does not shrink there the way it can with curves such as the sigmoid, which flatten out at both ends. That is a large part of why deep networks train well with it.

What is the known drawback? The dying ReLU problem. A neuron whose input stays negative outputs 0 and receives a gradient of 0, so its weights stop changing, and it can stop learning for good. Variants such as the leaky ReLU keep a small slope on the negative side to avoid this.

An everyday picture

Think of a one-way valve on a water pipe. Water pushing forward flows through unchanged, so a bigger push gives a bigger flow. Water pushing backward meets a closed valve and stops at zero. The neuron lets through only the part of the signal that points in the forward direction.

Worked example: A smart fan that depends on the window

A smart fan uses one neuron to decide how hard to run. Its inputs are x1=3x_1 = 3, the number of degrees the room is above a comfortable temperature, and x2x_2, which is 1 when a window is open and 0 when it is shut. The weights are w1=0.5w_1 = 0.5 per degree and w2=−2w_2 = -2 for the open window, because open windows cool the room. The bias is b=0.25b = 0.25. The fan’s strength is on a made-up scale with no unit. We find the output with the window open, then with the window shut.

  1. Compute the weighted sum with the window open. Here x2=1x_2 = 1. The first input contributes 0.5×3=1.50.5 \times 3 = 1.5, and the open window contributes (−2)×1=−2(-2) \times 1 = -2. Those two products are added, which gives 1.5−2=−0.51.5 - 2 = -0.5, so far the signal points toward turning the fan off.
  2. Add the bias. The bias 0.250.25 is added to the weighted sum, so z=−0.5+0.25=−0.25z = -0.5 + 0.25 = -0.25. The total is negative, which means the room would be cooled by the open window, so the fan should not work hard.
  3. Apply ReLU to the negative total. ReLU compares the total with zero, max⁡(0,−0.25)=0\max(0, -0.25) = 0. The negative total loses, so the output is 0. The fan is off, and the neuron has switched itself off for this input.
  4. Now shut the window. With the window closed, x2=0x_2 = 0, so the window term is (−2)×0=0(-2) \times 0 = 0. The weighted sum is 1.5+0=1.51.5 + 0 = 1.5, and adding the bias gives z=1.5+0.25=1.75z = 1.5 + 0.25 = 1.75. The total is positive, so the fan should run.
  5. Apply ReLU to the positive total. The comparison is max⁡(0,1.75)=1.75\max(0, 1.75) = 1.75. A positive total passes through unchanged, so the output is 1.75 on the made-up scale, a strength that rises as the room gets warmer.

Answer: With the window open, the output is 0, so the fan stays off, because the negative total was switched to zero. With the window shut, the output is 1.75, so the fan runs. The same ReLU rule either passes a positive total through unchanged or turns a negative total into zero.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

Why not use a straight line instead?

A stack of straight-line layers is still one straight line overall. The bend that ReLU adds is what lets stacked layers represent curved patterns.

What is the derivative of ReLU?

It is 1 for positive inputs and 0 for negative inputs. The point exactly at zero is handled by convention in code, usually as 0.

Why is ReLU so popular?

It is fast to compute, it does not flatten out large values the way a sigmoid does, and it trains well in deep networks. Those three points together made it a common default for hidden layers.

Sources

  1. Rectifier (neural networks), Wikipedia
  2. Activation function, Wikipedia

| All AI & ML formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: ai-ml/relu-activation.md.