Neural Networks • Neural Network Foundations • 12 min read

Neural Networks: Neurons, Layers, Weights, and Biases

Think of a network as connected calculations

Suppose you want software to estimate whether a photo contains a handwritten digit. The program cannot rely on one fixed pixel rule because the same digit can be written in many shapes. A neural network learns numerical transformations that combine pieces of input information into a prediction.

At the smallest level, an artificial neuron takes numbers, multiplies each by a weight, adds a bias, and usually passes the result through an activation function. A layer is a group of such units. Connecting layers allows the network to build more complicated patterns than a single linear calculation can represent.

For a concrete example, imagine two input measurements: the height and width of a handwritten mark. A neuron might give height a positive weight, width a negative weight, and use the bias to shift its decision boundary. During training, the weights and bias are adjusted based on examples. Real image networks use many more inputs and richer arrangements of layers, but the basic operation is recognizable.

Importantly, an artificial neuron is a mathematical component, not a tiny digital brain. The next sections introduce the exact notation, explain why nonlinear activation matters, and show how these pieces become an entire model.

An artificial neural network (ANN) is a computational model made of connected processing units that transform inputs into outputs using adjustable numerical parameters. Many neural networks learn these parameters from data so that they can classify inputs, predict numerical values, or generate representations useful for other tasks.

Neural networks are a major family of models in machine learning. Deep learning generally refers to machine learning with networks containing multiple layers of learned transformations. Despite the name, artificial neurons are simplified mathematical operations, not faithful simulations of biological brain cells.

This article focuses on the components and computations that make a neural network work. The next articles examine how information and gradients propagate through networks and how networks are trained.

1. The fundamental idea

Consider a model that predicts whether a transaction is likely to be fraudulent. Inputs might include the transaction amount, account activity, and distance from the usual purchase location. A neural network takes numerical representations of those inputs, combines them with learned parameters, and produces an output such as a score or estimated probability.

The essential distinction from a hand-written rule system is that the network’s numerical parameters can be estimated from examples instead of specifying every decision boundary manually.

A network defines a parameterized function:

y^=fθ(x),\hat{y}=f_{\theta}(\mathbf{x}),

where:

  • x\mathbf{x} is an input vector.
  • fθf_{\theta} is the network’s computation.
  • θ\theta denotes its learnable parameters, typically weights and biases.
  • y^\hat{y} is the network’s output or prediction.

The architecture determines which computations are possible. Training determines the particular parameter values used by those computations.

2. What is an artificial neuron?

A basic artificial neuron computes a weighted sum of its inputs, adds a bias, and applies an activation function:

z=∑i=1nwixi+b,z=\sum_{i=1}^{n}w_i x_i+b, a=ϕ(z).a=\phi(z).

Here, xix_i is input ii, wiw_i is its weight, bb is the bias, zz is the pre-activation value, ϕ\phi is the activation function, and aa is the neuron’s output.

Worked calculation

Suppose a neuron has two inputs:

x=[23],w=[0.5−0.25],b=0.1.\mathbf{x}=\begin{bmatrix}2\\3\end{bmatrix},\quad \mathbf{w}=\begin{bmatrix}0.5\\-0.25\end{bmatrix},\quad b=0.1.

Its weighted sum is:

z=(0.5)(2)+(−0.25)(3)+0.1=0.35.z=(0.5)(2)+(-0.25)(3)+0.1=0.35.

If the neuron uses the ReLU activation, ϕ(z)=max⁡(0,z)\phi(z)=\max(0,z), its output is:

a=max⁡(0,0.35)=0.35.a=\max(0,0.35)=0.35.

A different input, set of weights, or activation function could produce a different output. One neuron performs a small computation; many connected neurons can represent more complex relationships.

3. Weights: how inputs influence computations

A weight is a learnable parameter that scales an input or intermediate value. The magnitude and sign of a weight affect the weighted sum, but its interpretation depends on the other inputs, the network architecture, and the activation functions.

For a fixed input representation:

  • A positive weight increases the weighted sum as its associated input increases.
  • A negative weight decreases the weighted sum as its associated input increases.
  • A zero weight contributes nothing from that connection to the sum.

A weight does not by itself reveal the real-world importance or causal effect of a feature. Other weights and nonlinear transformations can change the final result.

In a dense neural-network layer, the weights are collected into a matrix. This lets the layer compute many neurons efficiently using linear algebra.

4. Biases: adjustable offsets

A bias is an additional learnable value added to a weighted sum. It lets a neuron shift its response independently of its inputs.

Consider a neuron without an activation function:

y=wx+b.y=wx+b.

If b=0b=0, the resulting line must pass through the origin. If b≠0b\ne0, the line can have a nonzero intercept. In a neuron with an activation function, changing the bias can shift when or how strongly the neuron activates.

Not every neural-network component uses a bias, but biases are common in dense and convolutional layers.

5. Layers and network architecture

A layer groups computations that operate on an input representation. In a basic feedforward multilayer perceptron (MLP), information moves through an ordered series of layers.

Input representation

The network receives an input vector, such as four measured attributes of a flower or a sequence of numeric features describing a transaction. The term input layer usually refers to this entry representation; it is not necessarily a layer with trainable parameters.

Hidden layers

Hidden layers transform incoming values into intermediate representations. A dense hidden layer computes weighted combinations of all inputs, then usually applies a nonlinear activation function.

Output layer

The output layer maps the final intermediate representation to values suitable for the task. For example:

TaskTypical outputCommon final activation
Predict a numerical targetOne or more real-valued predictionsLinear (no additional nonlinearity)
Binary classificationOne score or probabilitySigmoid for a probability
Multiclass classificationOne score per classSoftmax for class probabilities
Multilabel classificationOne score or probability per labelSigmoid for each label

An implementation may output raw logits rather than explicit probabilities because certain loss functions combine the activation and loss calculation for numerical stability.

Architecture illustration

Feedforward neural network with three input features, four hidden neurons, and two outputs
A fully connected feedforward network with three inputs, one hidden layer of four neurons, and two output neurons. The drawing shows connections, not learned weight values.

Depth and width

Depth usually describes the number of successive learned transformations, while width describes how many units are in a layer. Conventions for counting the input and output layers vary, so specify the architecture rather than relying only on a layer count.

A network with more layers is not automatically better. Appropriate size depends on the task, available data, compute budget, and risk of overfitting.

6. Activation functions and nonlinearity

An activation function transforms a neuron’s pre-activation value. Nonlinear activations are essential for ordinary multilayer perceptrons to represent nonlinear functions.

Without nonlinear activations, composing dense layers yields another affine transformation. For example, two layers with linear computations become:

y=W2(W1x+b1)+b2=(W2W1)x+(W2b1+b2).\mathbf{y}=W_2(W_1\mathbf{x}+\mathbf{b}_1)+\mathbf{b}_2 =(W_2W_1)\mathbf{x}+(W_2\mathbf{b}_1+\mathbf{b}_2).

That expression has the same general form as a single affine layer. Nonlinearity enables networks to construct richer decision boundaries and representations.

ActivationDefinition or behaviorCommon use
ReLUmax⁡(0,z)\max(0,z)Hidden layers in many networks
Sigmoid1/(1+e−z)1/(1+e^{-z}), mapping to (0,1)(0,1)Binary-probability outputs and gating
TanhMaps values to (−1,1)(-1,1)Some recurrent networks and hidden units
SoftmaxConverts a vector of scores to positive values summing to 1Mutually exclusive class probabilities
GELUSmoothly scales inputs according to their valuesMany Transformer feed-forward blocks

Softmax operates on a vector, rather than acting as a separate scalar transformation on each output independently:

softmax⁡(zi)=ezi∑j=1Kezj.\operatorname{softmax}(z_i)=\frac{e^{z_i}}{\sum_{j=1}^{K}e^{z_j}}.

An activation should be chosen with the task, training procedure, and loss function in mind.

7. Matrix form of a dense layer

For a column-vector input x∈Rn\mathbf{x}\in\mathbb{R}^{n} and a dense layer containing mm neurons:

z=Wx+b,a=ϕ(z),\mathbf{z}=W\mathbf{x}+\mathbf{b},\qquad \mathbf{a}=\phi(\mathbf{z}),

where:

  • W∈Rm×nW\in\mathbb{R}^{m\times n} is the weight matrix.
  • b∈Rm\mathbf{b}\in\mathbb{R}^{m} is the bias vector.
  • z,a∈Rm\mathbf{z},\mathbf{a}\in\mathbb{R}^{m} are the layer’s pre-activations and activations.

For several layers, the output of one becomes the input to the next:

a(ℓ)=ϕ(ℓ)(W(ℓ)a(ℓ−1)+b(ℓ)).\mathbf{a}^{(\ell)}=\phi^{(\ell)}\left(W^{(\ell)}\mathbf{a}^{(\ell-1)}+\mathbf{b}^{(\ell)}\right).

Here ℓ\ell identifies the layer and a(0)=x\mathbf{a}^{(0)}=\mathbf{x} is the original input. Matrix shapes must agree at every step.

How many parameters?

A dense layer with nn inputs and mm neurons has:

mn⏟weights+m⏟biases=m(n+1)\underbrace{mn}_{\text{weights}}+\underbrace{m}_{\text{biases}}=m(n+1)

learnable parameters when each neuron has a bias.

For example, a dense layer with four inputs and three neurons has 4(3)+3=154(3)+3=15 parameters. If a second dense layer maps those three outputs to one output, it adds 3(1)+1=43(1)+1=4, for 19 total parameters.

The parameter count matters for memory and computation, but it does not alone determine model quality or explainability.

8. Build a tiny network with NumPy

The following example performs a forward pass through a two-layer network. The weights are chosen manually for demonstration. Because no training occurs, the output is not a learned prediction.

import numpy as np

# One sample with three numerical input features.
x = np.array([1.0, 2.0, -1.0])

# Hidden layer: 3 inputs -> 2 neurons.
W1 = np.array([
    [0.2, -0.1, 0.5],
    [0.7, 0.3, -0.4],
])
b1 = np.array([0.1, -0.2])

# Output layer: 2 hidden values -> 1 output score.
W2 = np.array([[0.6, -0.3]])
b2 = np.array([0.05])

def relu(values):
    return np.maximum(0.0, values)

def sigmoid(values):
    return 1.0 / (1.0 + np.exp(-values))

hidden_pre_activation = W1 @ x + b1
hidden = relu(hidden_pre_activation)
output_score = W2 @ hidden + b2
output_probability = sigmoid(output_score)

print("Hidden pre-activations:", hidden_pre_activation)
print("Hidden activations:", hidden)
print("Output probability:", output_probability.item())

Expected output, rounded:

Hidden pre-activations: [-0.3  1.5]
Hidden activations: [0.  1.5]
Output probability: 0.401312339887548

The sigmoid converts the final score into a number between zero and one. Interpreting that number as a meaningful probability requires an appropriate task, training procedure, and evaluation; a sigmoid alone does not make a network calibrated or accurate.

What changes during training?

During training, an optimizer updates the weights and biases based on a loss computed from training examples. The network’s structure and computations remain defined by its architecture, although some training methods can also change or select the architecture.

The distinction is useful:

  • Forward pass: compute outputs from the current parameters.
  • Loss: measure mismatch between outputs and learning targets.
  • Backpropagation: calculate how the loss changes with parameters.
  • Optimizer step: use gradients to update parameters.

See Forward Propagation and Backpropagation for the computational details.

9. Why neural networks are useful

Neural networks can learn representations suited to different tasks. Depending on their architecture and training data, they are used in:

  • Classification: identifying image categories or classifying text.
  • Regression: predicting continuous quantities, such as energy usage.
  • Computer vision: processing image and video inputs.
  • Natural language processing: modeling and generating language.
  • Speech and audio: recognizing speech or generating sound.
  • Representation learning: producing embeddings used in retrieval and other downstream systems.

Different architectures impose different structural assumptions. A basic dense network is useful for understanding the core mathematics, but a convolutional network, recurrent network, or Transformer uses additional operations suited to particular information structures.

10. Limitations and common misunderstandings

More neurons do not guarantee better performance

Larger networks can fit more complex functions, but they may need more training data, computation, regularization, and careful evaluation. Architecture choice is a trade-off rather than a competition to maximize parameter count.

Weights are not a simple explanation of decisions

Individual weights usually cannot be interpreted as direct feature-importance scores. Predictions depend on combinations of weights, activations, interactions, and input representations.

Output scores are not automatically reliable probabilities

A classifier may be overconfident, poorly calibrated, or wrong on inputs unlike its training data. Evaluation and calibration are separate concerns from producing a numerical score.

Networks can memorize training-specific patterns

If a model fits the training data but performs poorly on new samples, it may be overfitting. Validation data, suitable regularization, representative datasets, and robust evaluation help detect and address this problem.

Neural networks are not the only machine-learning approach

Linear models, decision trees, ensembles, and other methods can outperform a neural network for a particular dataset or engineering constraint. The best choice depends on the task, not the popularity of the model family.

11. Check your understanding

  1. What are the roles of a weight, a bias, and an activation function in a neuron?
  2. Why can several dense layers with only linear activations be replaced by one affine transformation?
  3. What are the shapes of WW and b\mathbf{b} for a layer with five inputs and eight neurons?
  4. How many learnable parameters are in that layer if every neuron has a bias?
  5. What is the difference between computing a forward pass and training a network?
Show worked answers
  1. A weight scales a corresponding input; a bias adds an offset; an activation transforms the weighted sum, often nonlinearly.
  2. The composition of affine transformations remains affine, so it does not introduce new nonlinear behavior.
  3. W∈R8×5W\in\mathbb{R}^{8\times5} and b∈R8\mathbf{b}\in\mathbb{R}^{8}.
  4. 8(5+1)=488(5+1)=48 parameters.
  5. A forward pass computes outputs using current parameters. Training also measures loss and adjusts learnable parameters using an optimization procedure.

Prerequisites

Continue learning

The follow-on articles are part of the planned knowledge map; their links become active as those pages are published.

13. References and further reading

Related articles in

  • Convolutional and Recurrent Neural Networks — Understand convolutional networks for spatial data and recurrent networks for sequences, including CNN filters, RNN state, LSTMs, GRUs, and practical PyTorch examples.
  • Deep Learning with PyTorch — Build, train, evaluate, and save a neural network with PyTorch using tensors, automatic differentiation, datasets, and optimization loops.
  • Forward Propagation and Backpropagation — Learn how neural networks compute predictions with forward propagation and calculate parameter gradients with backpropagation, using the chain rule and a worked example.

Image preview

Fit