What is a neural network?
Last updated: 2026-11-23
A neural network is a formula that turns input numbers into a prediction by passing them through a layer of simple units. Each unit takes a weighted sum of the inputs and applies a fixed nonlinear function, and a final step combines the results of the units into the answer.
Start learning No account needed
The weights are numbers chosen by fitting the network to data, which is the training step that understand backpropagation covers.
1. The pieces
An Introduction to Statistical Learning describes a network with one hidden layer like this. The inputs X1 to Xp make up the input layer. Each of K hidden units computes a weighted sum of the inputs plus a constant, w0 + w1 X1 + … + wp Xp, and passes it through an activation function g to get that unit's activation. The book writes w21 for hidden unit 2's weight on input 1. The output layer then forms one more weighted sum, of the K activations plus a constant: f(X) = β0 + β1 A1 + … + βK AK. That last step is a linear regression on the activations. You pick K, and the weights and constants are estimated from data.
The activation function is chosen in advance. Early networks used the sigmoid, g(z) = 1 / (1 + e−z), which is the function logistic regression uses to turn a linear function into a probability between 0 and 1. The book calls ReLU, the rectified linear unit, the preferred choice in modern networks. It returns 0 when z is negative and z otherwise.
The hidden units are not observed in the data. The book describes them as new features built from the inputs, with functions that are learned during training. The name comes from an early comparison of hidden units with neurons in the brain, where an activation near one is firing and near zero is silent. Each unit is still only the formula above.
2. A worked example: two inputs and two hidden units
Take two inputs, X1 = 2 and X2 = 1, two hidden units that use ReLU, and one output. The weights are made up for this page.
| Unit | Constant | Weight on first input | Weight on second input |
|---|---|---|---|
| Hidden unit 1 | −1 | 1 | 2 |
| Hidden unit 2 | 2 | −1 | −3 |
| Output (inputs are A1 and A2) | 1 | 0.5 | 2 |
Hidden unit 1 computes z1 = −1 + 1 × 2 + 2 × 1 = 3, and ReLU(3) = 3, so A1 = 3. Hidden unit 2 computes z2 = 2 + (−1) × 2 + (−3) × 1 = −3, and ReLU(−3) = 0, so A2 = 0 and that unit is silent for this input. The output is f = 1 + 0.5 × 3 + 2 × 0 = 2.5.
Now change one weight, w21, from −1 to 1. Then z2 = 2 + 1 × 2 + (−3) × 1 = 1, so A2 = 1, and the output becomes f = 1 + 0.5 × 3 + 2 × 1 = 4.5. One weight moved, one hidden unit switched on, and the prediction went from 2.5 to 4.5. The network has 2 × 3 + 3 = 9 numbers to estimate, three for each hidden unit and three for the output.
Training means choosing those nine numbers. Suppose the true value for this input is y = 3. The squared error is (3 − 2.5)2 = 0.25 with the first weights and (3 − 4.5)2 = 2.25 after the change, so the change made this one prediction worse. The book fits a network by choosing the weights that minimize the sum of these squared errors over the training cases. It uses gradient descent, which moves the weights a small step against the gradient of that sum, and backpropagation, which finds the gradient with the chain rule. The book notes that the problem is nonconvex, so it has several solutions, and a fit can end at a local minimum. Values from the script, run on 2026-11-23: z = 3, -3; activations = 3, 0; f = 2.5 and after w21 = 1: z = 3, 1; activations = 3, 1; f = 4.5. They come from a short script, neural-network-example.mjs, that does the same arithmetic.
3. Why the activation function matters
The book says the nonlinearity in the activation function is essential, since without it the model collapses into a simple linear model in the inputs. The same weights show it. If g(z) = z, then f = 1 + 0.5 (−1 + X1 + 2 X2) + 2 (2 − X1 − 3 X2) = 4.5 − 1.5 X1 − 5 X2. At X = (2, 1) that gives −3.5, because the linear version lets hidden unit 2 pass its −3 through, and 1 + 1.5 − 6 = −3.5, where ReLU gave 2.5.
With ReLU the network is not linear. Along the line through (0, 0), (2, 1) and (4, 2), a linear function changes by the same amount at each step. This network gives 5, 2.5 and 4.5, which change by −2.5 and then +2.0. The book also shows what a nonlinear activation can build. With g(z) = z2 and the right weights, two hidden units give f(X) = X1 × X2, an interaction between the inputs, and at X = (3, 2) the hidden values are 25 and 1, so f = (25 − 1) / 4 = 6. The book adds that in practice you would use sigmoid or ReLU, because a squared activation gives only second-degree polynomials.
4. A common misconception: more layers make a network more flexible on their own
It is natural to think that stacking layers adds power by itself. What each layer adds is a weighted sum, and the activation function between layers is what lets the stack do more than one weighted sum could. The book states the collapse for its one-hidden-layer model. We also checked in the script that two stacked layers of weighted sums with no activation function reduce to a single formula, f = −2.5 − 12 X1 + 13 X2 for the weights in the script, at all the points we tried.
The book adds that a single hidden layer with a large number of units can in theory approximate most functions, but that learning a good solution is made much easier with multiple layers, each of modest size. Its digit-recognition network has 784 inputs, two hidden layers of 256 and 128 units, and 10 outputs, which makes 235,146 parameters: 785 × 256 = 200,960 into the first layer, 257 × 128 = 32,896 into the second and 129 × 10 = 1,290 into the output.
5. Test yourself
Close this page and compute the output for X1 = 1 and X2 = 0 with the first set of weights, saying which hidden unit is silent. Then explain in your own words why removing the activation function turns this network into a linear regression on X1 and X2. Reopen the page and compare. The output should be 3, with hidden unit 1 silent, and the first step where you slipped is the part to study again. For the general method, see how to test yourself.
What the sources found, and their limits
An Introduction to Statistical Learning with Applications in R, second edition, chapter 10 (Deep Learning), sections 10.1, 10.2 and 10.7, printed pages 404 to 409 and 434 to 436. Gareth James, Daniela Witten, Trevor Hastie and Robert Tibshirani, free to read. It gives the one-hidden-layer model in two steps, the sigmoid and ReLU activations, the hidden units as derived features that are learned, the statement that without the nonlinearity the model collapses to a linear model, the g(z) = z2 example that produces X1 × X2, the digit network and its 235,146 parameters, and the squared-error objective with the outline of gradient descent and backpropagation, including that the problem is nonconvex. Source: statlearning.com, which links the free PDF; we read the corrected June 2023 PDF on 2026-11-23.
Limits: we did not read the sections on convolutional and recurrent networks or the labs, and in section 10.7 we read the fitting outline and not the details of stochastic gradient descent, so the page says nothing on those. The book states the collapse for its one-hidden-layer model, and the two-layer case is our own check in the script. The inputs, weights and all numbers in the worked example are made up, and the page uses ReLU where the book's own worked example uses a squared activation.
How Professor Turing helps
Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start.
Bring a topic you are studying, such as why a network needs an activation function. Its first reply asks what you already know before it teaches anything. If you answer with a bare guess, such as a term, it asks how you got there instead of saying right or wrong, and when you stay stuck it changes its approach and makes the next step smaller instead of giving the final answer. Later in a session it can offer a short test without help, scored apart from the tutoring, so you can tell what you can do alone from what the tutor carried you through.
It does not read or mark a written answer, and it does not write your explanation for you, so the explanation has to be yours. You must be 18 or older, and conversations are deleted after 7 days.
FAQ
How many weights does a neural network have? For one hidden layer with p inputs and K hidden units, each hidden unit has a constant and p weights, and the output has a constant and K weights, so the total is K(p + 1) + K + 1. Our example has p = 2 and K = 2, which gives 9. The book's digit network, with 784 inputs, hidden layers of 256 and 128 units and 10 outputs, has 235,146.
What does the activation function do? It is a fixed nonlinear function applied to each hidden unit's weighted sum. Without it the network reduces to a linear model in the inputs. In our example ReLU turns hidden unit 2's value of -3 into 0, so that unit adds nothing for that input, and the output is 2.5 where the linear version would give -3.5.
Start with what you're working on
Tell the tutor which topic you are studying and let it ask you the questions.
Start learning No account needed
See also: all study guides