keepcalculator

06 Numbers and Powers

Neural Network Layers: How Predictions Work

Card No. 06·49537 · Updated · Standard formula, shown below

Weighted sum 0.30
Sigmoid output
0.5744
Result
Input value
1
You entered
Weight 1
0.5
You entered
You enter
Input value, Weight 1, Weight 2, Bias
You get
Weighted sum, Sigmoid output
Rounding
2 dp · 4 dp

Neural networks make predictions by passing input data through a series of layers, each of which transforms the data step by step until a final output emerges. You feed in numbers (like pixel values or text scores), and the network applies learned weights and biases at each layer to produce a result, such as a class label or a numeric value. This article explains exactly how that layered process works, why it works, and how to interpret what each layer does.

Formula

For a single neuron (the basic unit of a layer), the output is computed as:

z = (input × weight1) + (input × weight2) + bias

Then an activation function is applied. The sigmoid activation used here is:

a = 1 / (1 + e-z)

  • Input value (t) – the raw feature you provide (e.g., a pixel brightness, a word frequency).
  • Weights (w1, w2) – numbers the network learned during training; they determine how much each input matters.
  • Bias (b) – a learned constant that shifts the weighted sum, allowing the neuron to activate even when inputs are zero.
  • z – the weighted sum before activation.
  • a – the final output of the neuron, typically between 0 and 1 for sigmoid.

Worked Example

Using the default values from the calculator: input = 1, weight1 = 0.5, weight2 = -0.3, bias = 0.1.

  1. Multiply each input by its weight: 1 × 0.5 = 0.5 and 1 × -0.3 = -0.3.
  2. Sum those products: 0.5 + (-0.3) = 0.2.
  3. Add the bias: 0.2 + 0.1 = 0.3. This is z.
  4. Apply sigmoid: 1 / (1 + e-0.3) ≈ 1 / (1 + 0.7408) ≈ 0.5744.

The calculator shows z = 0.30 and a = 0.5744, matching the step-by-step result.

What Is a Neural Network Layer?

A layer is a collection of neurons that all receive the same input (from the previous layer or from the raw data) but each has its own set of weights and bias. The output of one layer becomes the input to the next. The first layer is called the input layer, the last is the output layer, and any layers in between are hidden layers.

For example, in an image recognition network, the input layer might have 784 neurons (one per pixel in a 28×28 image). The hidden layers then detect patterns: edges, shapes, parts of objects, and finally whole objects. The output layer might have 10 neurons, one for each digit (0–9), and the neuron with the highest value indicates the predicted digit.

How Information Flows Through Layers

The process is called forward propagation. Here’s the step-by-step flow:

  1. Input data is fed into the input layer as a vector of numbers.
  2. Each neuron in the first hidden layer computes a weighted sum of all inputs, adds its bias, and applies an activation function.
  3. The outputs of that hidden layer become the inputs to the next layer.
  4. This repeats through every hidden layer until the output layer produces the final prediction.
  5. The network compares its prediction to the true answer (during training) and adjusts weights to reduce error.

Each layer essentially learns a new representation of the data. Early layers capture simple features (edges, textures), middle layers combine them into parts (eyes, wheels), and later layers combine parts into wholes (faces, cars). This is why deep networks (many layers) can solve complex tasks like speech recognition or language translation.

Activation Functions: What Makes Layers Non-Linear

Without activation functions, stacking layers would just produce a linear combination of the input—no more powerful than a single layer. Activation functions introduce non-linearity, allowing the network to model complex patterns.

  • Sigmoid – outputs between 0 and 1, useful for probabilities but can cause vanishing gradients.
  • ReLU (Rectified Linear Unit) – outputs max(0, z), very common in hidden layers because it is fast and avoids vanishing gradients.
  • Softmax – used in the output layer for multi-class classification; it converts raw scores into probabilities that sum to 1.

For instance, if the final layer of a digit classifier uses softmax, the output might be [0.01, 0.02, 0.90, 0.03, …], meaning the network is 90% confident the digit is “2”.

How Many Layers Should You Use?

The number of layers and neurons is called the network’s architecture. There is no universal rule, but here are practical guidelines:

  • Simple problems (e.g., linear regression, basic classification) often need no hidden layers—just input and output.
  • Moderate problems (e.g., image recognition on small datasets) benefit from 1–3 hidden layers.
  • Complex tasks (e.g., natural language processing, self-driving cars) use dozens or even hundreds of layers (deep learning).

Start with a small network and increase complexity only if performance on validation data is poor. Too many layers can cause overfitting, where the network memorizes training data but fails on new data.

Common Problems with Layers

Several issues can arise when training layered networks:

  • Vanishing gradients – In deep networks, gradients can become extremely small during backpropagation, so early layers learn very slowly. ReLU and batch normalization help.
  • Overfitting – The network becomes too specialized to training data. Dropout (randomly ignoring neurons during training) and regularization are common fixes.
  • Underfitting – The network is too simple to capture the pattern. Add more layers or neurons, or train longer.
  • Exploding gradients – Gradients become too large, causing unstable training. Gradient clipping or lower learning rates help.

These are practical concerns that engineers address when designing real-world systems.

Layers vs. Other Prediction Methods

Layered neural networks are not the only way to make predictions. Traditional machine learning models like decision trees or support vector machines (SVMs) work directly on features without learning intermediate representations. Neural networks are more flexible and often more accurate on unstructured data (images, audio, text), but they require more data and computational power.

For tabular data (spreadsheets), simpler models often perform just as well and are easier to interpret. For images or speech, deep layered networks are usually the best choice.

Frequently Asked Questions

What exactly does a neuron in a hidden layer do?

A neuron receives inputs from all neurons in the previous layer, multiplies each by its weight, sums them, adds a bias, and applies an activation function. The result is a single number that is passed to the next layer.

Why do deep networks perform better than shallow ones?

Deep networks can learn hierarchical features. A shallow network might only learn simple patterns, while a deep network can combine those patterns into increasingly complex concepts, which is crucial for tasks like recognizing objects or understanding language.

Can I use a neural network without hidden layers?

Yes. A network with only input and output layers is equivalent to linear regression (if no activation) or logistic regression (if sigmoid is used). It works for linearly separable problems but fails on non-linear patterns.

How do I choose the number of neurons per layer?

There’s no exact formula. A common practice is to start with a number between the input and output sizes, then experiment. For example, if input has 100 features and output has 10 classes, try 50–100 neurons in one hidden layer, then adjust based on validation accuracy.

What is the role of the output layer?

The output layer produces the final prediction. For regression, it has one neuron with no activation (or linear). For binary classification, it has one neuron with sigmoid. For multi-class classification, it has one neuron per class with softmax to yield probabilities.

Do all layers use the same activation function?

No. Hidden layers typically use ReLU or tanh, while the output layer uses a function suited to the task (sigmoid for binary, softmax for multi-class, linear for regression). Mixing activation functions is standard.

Related

Formula used
in t | Input value | - | 1 | 0
in w1 | Weight 1 | - | 0.5 | -10 | 10
in w2 | Weight 2 | - | -0.3 | -10 | 10
in b | Bias | - | 0.1 | -10 | 10
out z | Weighted sum | - | t * w1 + t * w2 + b | 2
out a | Sigmoid output | - | 1 / (1 + exp(-z)) | 4

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →