TL;DR
A feedforward neural network passes an input through a sequence of layers. Each layer does a matrix multiplication of its input by a weight matrix, adds a bias vector, and applies an activation function elementwise. Information only flows forward, from input to output, with no loops. The activation functions are what matter: they stop the layers from collapsing into one linear map, so the whole stack can represent curved relationships.
This is the basic architecture behind most of deep learning. Convolutional networks, transformer feed-forward blocks, and the output heads of most larger models are all variations on it.
Where you'll see it: as the classifier that sits on top of image features, as the per-token feed-forward block inside every transformer layer, and as the function approximator inside reinforcement learning agents.
Intuition
Folding a sheet of paper
Think of the input as a point on a sheet of paper. A linear layer (a Linear Transformation) can stretch, rotate, shear, or flip the sheet, but it always keeps straight lines straight. An activation function bends the sheet at a crease. Each layer adds another round of stretching and folding. After enough rounds, a flat sheet can be folded into a complicated shape, and the output is read off where each point ends up.
Training is the process of choosing where to stretch and where to fold, so that points that should share a label land together and points that should differ land apart.
flowchart LR x1[x1] --> h1[h1] x1 --> h2[h2] x1 --> h3[h3] x2[x2] --> h1 x2 --> h2 x2 --> h3 h1 --> y[y] h2 --> y h3 --> y
The diagram shows a network with two inputs, a hidden layer of three neurons, and one output. Every arrow carries a weight, and every neuron in one layer is connected to every neuron in the next. That is why these networks are called fully connected or dense. The hidden layer is hidden only because we never look at its values directly; the network is free to use them however it likes.
Why the bend matters
Suppose there were no activation functions. Then layer one computes , and layer two computes . Expanding gives , which is a single linear map with a single bias. A hundred such layers would still be one matrix and one vector. Adding nonlinearity between layers is what makes depth useful.
The math
A feedforward network with layers is a sequence of functions. Set , the input vector. For each layer :
Here is a weight matrix of size , where is the number of neurons in layer . The vector is the bias, of length . The function is an activation applied to each entry separately, and is called the pre-activation. The last layer is usually left without an activation, or with one suited to the task, so that or (the Softmax turns scores into probabilities) for classification.
The layers between input and output are called hidden layers. A network with several of them is called deep.
The forward pass
Computing from is the forward pass. It is just the definition above, run from to . Each layer costs one matrix-vector product, which is multiply-adds.
Counting parameters
The trainable parameters are every weight and bias. A layer with inputs and outputs has parameters. The total is the sum over layers. This count matters because it sets memory use, and a network with many more parameters than training examples can memorise the training set.
Training
The network is trained by choosing all weights and biases to minimise a Loss Function averaged over the training set. For classification the usual loss is the Cross-Entropy Loss on the softmax output. The gradient of the loss with respect to every parameter is computed with the chain rule, running backwards through the layers. That procedure is Backpropagation, and the parameters are updated with a rule such as Gradient Descent or a variant of it.
Universal approximation
A single hidden layer with enough neurons and a suitable bend can approximate any continuous function on a bounded region to any accuracy. Cybenko proved this for sigmoid activations in 1989, and Hornik extended it to a broader class of activations in 1991. The theorem is an existence result. It says nothing about how many neurons are needed, how to find the weights, or whether the network will generalise to new inputs. Depth often gets the same accuracy with far fewer parameters, which is why practical networks are deep.
Worked examples
The XOR function takes two bits and outputs 1 when they differ: , , , . No single line separates the 1s from the 0s, so no linear model computes it.
Use two ReLU hidden units, :
- output
Check each input:
- : , , so . Correct.
- : , , so . Correct.
- : same as the previous case, so . Correct.
- : , , so . Correct.
The hidden layer folds the input so that lands on the same side as . Remove the ReLU and the same arithmetic gives . That is linear, and it gets three inputs right but outputs 2 at instead of 0. No choice of linear weights fixes all four cases at once, so the bend is essential.
Take , one hidden layer of two ReLU units, and one linear output.
- Hidden pre-activations: . The first entry is . The second is .
- Apply ReLU: .
- Output: .
- Interpretation: the first hidden unit was switched off by the bend, so the output depends only on the second unit. The network used the nonlinearity to make one neuron inactive for this input.
A classifier for grayscale digits flattens each image to numbers, then uses two layers: and , one output per digit.
- First layer: parameters.
- Second layer: parameters.
- Total: parameters.
- Cost of a forward pass on a batch of 64 images: roughly million multiply-adds, which a laptop does in well under a millisecond with optimised matrix routines. Most of the parameters sit in the first layer, which is where the flattening throws away spatial structure. That is one reason convolutional networks replaced dense first layers for images.
Tradeoffs and failure modes
A feedforward network is a general, flexible function approximator. It is also a poor fit for some structures, and it is easy to overfit with it.
| Situation | Problem | Better choice |
|---|---|---|
| Data has spatial structure (images) | Flattening throws away neighbourhood information, and the parameter count grows fast | Convolutional Neural Network |
| Data is a sequence of variable length | A fixed input size cannot handle it directly | Recurrent Neural Network, or a transformer |
| Small tabular dataset | A large dense network memorises the training set | Gradient-boosted trees, or a small network with L2 Regularization |
| Very deep stack | Gradients vanish or explode during training | Residual connections, and careful Xavier (Glorot) Initialization or He (Kaiming) Initialization |
| Activation saturates (sigmoid at large inputs) | Gradients become near zero and learning stalls | Rectified Linear Unit (ReLU) or a similar activation |
| Layer outputs drift in scale during training | Learning becomes unstable | Layer Normalization |
Common failure modes include forgetting the activation between layers, which silently makes the whole stack linear, and choosing a hidden width so large that the network memorises noise. A good first check is to compare training loss with validation loss. A large gap means the network is memorising.
History
The idea of a neuron as a thresholded weighted sum comes from McCulloch and Pitts in 1943. Rosenblatt's perceptron, a single trainable layer, followed in 1958. In 1969 Minsky and Papert showed that single-layer perceptrons cannot compute XOR, and many researchers moved away from the approach for over a decade.
Multilayer networks trained by backpropagation came back into focus in the mid-1980s. Rumelhart, Hinton, and Williams popularised the method for hidden layers in 1986. The universal approximation results of Cybenko and Hornik followed in 1989 and 1991, which gave a theoretical reason to believe the architecture was expressive enough.
Practical progress was slower than the theory suggested. Dense networks were hard to train with sigmoid units, because gradients shrank through many layers. The switch to ReLU units and better initialisation in the 2010s made deep feedforward networks trainable at scale, and they became the building blocks of the architectures that followed.
Check yourself
QuestionWhy does a stack of layers with no activation function reduce to a single linear layer?Show answer
Each layer computes a matrix times the previous output plus a bias. Substituting one into the next gives , which is one matrix and one bias. Any number of linear layers collapses the same way, so depth adds nothing without a nonlinearity between layers.
QuestionA network has layers of size . How many parameters does it have?Show answer
The first layer has parameters. The second has . The total is .
QuestionIn the XOR example, why does the output use rather than ?Show answer
The second unit has to cancel the first one exactly when both inputs are 1. At , and , so , which is the XOR answer. With the output at would be 3, which is wrong.
QuestionYou train a dense network on 500 labelled photographs and it scores 99% on training data but 60% on new photos. What is happening, and what would you change first?Show answer
The network is overfitting: it has memorised the training photos rather than learning patterns that transfer. Dense layers on raw pixels have many parameters and little built-in structure, so this is common. The first changes to try are a smaller network, stronger regularisation such as weight decay or dropout, data augmentation, or a convolutional architecture that builds in the right structure for images.