Skip to main content
Translate content

To read content in another language, use your browser’s Translate page option (right-click the page or open the browser menu). Choose your preferred language; if offered, enable automatic translation. The site language menu changes navigation, not the original article. Interactive activities may remain in their original language.

AIFundamentalsEstimated time: 30 minUpdated November 26, 2026

How Neural Networks Work: From Artificial Neurons to Deep Learning

From a single artificial neuron to deep learning, step by step

Neural networks power photo recognition, voice assistants, translation and chat assistants, yet the core idea fits in a few lines: multiply, add, squash, repeat. In this lesson you will build an artificial neuron, see why activation functions matter, grow a network layer by layer and train a tiny network in your browser.

Diagram of a neural network with input, hidden and output layers of connected neurons

Learning objectives

  • Describe the inputs, weights, bias and output of an artificial neuron
  • Compute a weighted sum and apply an activation function
  • Compare step, sigmoid, tanh and ReLU
  • Explain layers, hidden layers and parameters
  • Describe training: forward pass, loss, backpropagation and gradient descent
  • Explain why hidden layers are needed and what "deep" learning means

Neural networks power photo recognition, voice assistants, translation and the chat assistants you may use every day. Yet the core idea fits in a few lines: multiply, add, squash, repeat. In about 30 minutes you will build an artificial neuron with your own hands, see why activation functions matter, grow a network layer by layer, and train a tiny network in your browser until it solves a problem a single neuron cannot. A self-graded quiz closes the lesson.

  • Time: 30 minutes
  • Level: beginner
  • Prerequisites: basic arithmetic
  • You need: a web browser

1. From brain-inspired idea to simple math

A neural network is a computer model made of many small units called artificial neurons, connected in layers. The idea was inspired, loosely, by the way neurons in the brain pass signals to each other. An artificial neuron is much simpler than a real one: it is just a small mathematical function.

A neural network does one job: it takes numbers in and produces numbers out. A photo becomes a list of pixel values, and the network outputs, say, the probability that the photo shows a cat. Producing that output from an input is called making a prediction.

Everything in this lesson, from a single neuron to a deep network, uses the same three operations: multiplications, additions and a simple function applied to the result.

2. The artificial neuron

An artificial neuron receives several inputs and gives one output. It works in two steps:

  1. Weighted sum. Each input is multiplied by a weight, which says how important that input is. All the results are added, together with a bias, a number that shifts the decision up or down.
  2. Activation. The sum goes through an activation function that produces the final output.
z = w₁·x₁ + w₂·x₂ + b   →   a = activation(z)

Imagine a neuron deciding "should I go for a walk?" from two inputs between 0 and 1: how nice the weather is, and how much free time you have. A large positive weight means that input pushes toward "yes". A negative weight pushes toward "no". The bias is your general mood: negative if you are lazy, positive if you love walking. Play with it:

Weather x₁: Free time x₂:
Weight w₁: Weight w₂: Bias b:
Activation function:

Experiments: set both weights to 0 and watch the output depend only on the bias. Make w₁ negative: now good weather pushes the answer toward "no". Raise the bias and see the neuron say "yes" even with weak inputs.

3. Activation functions

Without an activation function, a network would only ever compute weighted sums of weighted sums, which collapse into one big weighted sum. The activation function adds the non-linearity that lets networks learn complicated patterns. The four you just tried are the classics:

FunctionOutput rangeIdeaTypical use
Step0 or 1Fires only if z is zero or moreHistorical perceptron, simple yes/no
Sigmoidbetween 0 and 1A smooth S-curve, readable as a probabilityOutput of yes/no predictions
Tanhbetween −1 and 1A centered S-curveInside some networks
ReLU0 and aboveOutputs 0 if z is negative, otherwise zThe most common choice in hidden layers of deep networks

4. Layers: from one neuron to a network

One neuron can only make simple decisions. Real networks connect many neurons in layers:

  • The input layer holds the data (it does no computation).
  • One or more hidden layers transform it. Each neuron receives the outputs of the previous layer.
  • The output layer gives the final prediction.

Every connection has a weight and every neuron has a bias. These numbers are the network's parameters: they are what the network learns. Build a network and count them:

Hidden layers: Neurons per hidden layer:

Notice how fast the number of parameters grows. Networks used for images or language have millions to billions of them.

5. How a network learns

At the start, the weights are random, so the predictions are random too. Training improves them by repeating a loop:

  1. Forward pass: feed an example through the network and get a prediction.
  2. Loss: measure how wrong the prediction is, using a number called the loss (smaller is better).
  3. Backpropagation: work out, layer by layer from the end, how each weight contributed to the error.
  4. Update: nudge every weight slightly in the direction that reduces the loss. This is gradient descent.
w ← w − η · (∂Loss / ∂w)    (η = learning rate, the size of each nudge)

Let's watch it happen on tiny logic problems. The inputs are two bits. The task is AND (output 1 only if both inputs are 1), OR (output 1 if at least one is 1), or XOR (output 1 if exactly one is 1). First train a single neuron, then a small network:

Task: Model: Learning rate η:

Experiments:

  1. Train a single neuron on AND and OR: the loss falls and all four predictions become correct.
  2. Now choose XOR with a single neuron. It never gets all four right. One neuron can only draw one straight line to separate the cases, and no single line separates XOR.
  3. Switch the model to the small network and train on XOR: the hidden layer lets the network combine several lines, and it solves the problem.

This is the whole reason hidden layers exist. An epoch is one pass through all the training examples.

6. What makes it "deep learning"?

Deep learning simply means using neural networks with many hidden layers. Depth lets a network build understanding step by step. In an image network, early layers often respond to simple features such as edges, middle layers to shapes and textures, and later layers to whole objects. Nobody programs these features by hand: they emerge during training.

Deep learning works especially well when two things are available: a lot of data and a lot of computing power. It powers image recognition, speech recognition, translation and modern generative AI.

7. A neuron in Python

The neuron from section 2 takes only a few lines of Python:

import math

def sigmoid(z):
    return 1 / (1 + math.exp(-z))

def neuron(inputs, weights, bias):
    z = sum(x * w for x, w in zip(inputs, weights)) + bias   # weighted sum
    return sigmoid(z)                                          # activation

print(neuron([1, 0.5], [0.8, -0.4], 0.1))   # z = 0.8 - 0.2 + 0.1 = 0.7, output about 0.668

A layer is just many neurons reading the same inputs, and a network is layers chained together. Libraries such as PyTorch or TensorFlow do this efficiently on large amounts of data and compute the learning updates automatically. If you have not written Python yet, start with Write Your First Python Program.

8. Limits to keep in mind

  • Data hunger. Networks need many examples, and the quality of the data matters as much as the quantity.
  • Overfitting. A network can memorize its training examples and then perform poorly on new ones. That is why data is split into a training set and a test set.
  • Black box. With millions of parameters, it is hard to explain why a network gave a particular answer.
  • Bias. If the training data contains biases, the network can learn them.
  • Not magic. A prediction is a computed estimate, and for important decisions it should be checked.

9. Practice exercises

Compute or complete each answer, then check it. The feedback explains the solution.

10. Final quiz: test what you learned

Ten questions, one correct answer each. You get instant grading and every answer is explained.

Key takeaways

  • An artificial neuron multiplies inputs by weights, adds a bias, then applies an activation function.
  • Activation functions add the non-linearity that lets networks learn complex patterns.
  • Layers of neurons form a network; weights and biases are its parameters.
  • Training repeats forward pass, loss, backpropagation and a gradient descent update.
  • Hidden layers let a network solve problems, like XOR, that a single neuron cannot.
  • Deep learning uses many hidden layers and needs lots of data and computing power.

Frequently asked questions

What is a neural network in simple terms?

A neural network is a computer model made of layers of small units called neurons. Each neuron multiplies its inputs by weights, adds them up and applies a function. By adjusting the weights on many examples, the network learns to make useful predictions.

What is the difference between machine learning and deep learning?

Machine learning is the broad idea of learning patterns from data. Deep learning is a part of machine learning that uses neural networks with many hidden layers.

What is the role of weights and biases?

Weights control how strongly each input influences a neuron. The bias shifts the neuron's decision up or down. Together they are the parameters the network learns during training.

Why do neural networks need activation functions?

Without them, a network would only compute weighted sums of weighted sums, which is equivalent to a single weighted sum. Activation functions add non-linearity, so the network can learn complex relationships.

Do I need advanced math to start with neural networks?

No. Arithmetic is enough to understand a neuron. For deeper study you will meet vectors, derivatives and probability, but you can learn them step by step while experimenting with code.

Definitions

Artificial neuron

A small mathematical unit that multiplies its inputs by weights, adds a bias and applies an activation function.

Weight

A number that controls how strongly an input influences a neuron.

Bias

A number added to the weighted sum that shifts the neuron's decision up or down.

Activation function

A function applied to the weighted sum that adds non-linearity, such as sigmoid, tanh or ReLU.

Hidden layer

A layer of neurons between the input and the output of a network.

Loss

A number measuring how wrong a prediction is; training tries to make it smaller.

Gradient descent

A method that repeatedly nudges the weights in the direction that reduces the loss.

Deep learning

Machine learning with neural networks that have many hidden layers.

Worked examples

Weighted sum and sigmoid

A neuron has inputs x = (1, 0.5), weights w = (0.8, -0.4) and bias b = 0.1. Compute its sigmoid output.

z = 0.8x1 + (-0.4)x0.5 + 0.1 = 0.8 - 0.2 + 0.1 = 0.7. sigmoid(0.7) = 1 / (1 + e^-0.7) = about 0.668.

ReLU and step

For z = -1.5 and z = 2, compute ReLU(z) and the step function (1 if z >= 0, otherwise 0).

z = -1.5: ReLU = 0, step = 0. z = 2: ReLU = 2, step = 1.

Counting parameters

A network has 2 inputs, one hidden layer of 4 neurons and 1 output neuron. How many weights and biases does it have?

Input to hidden: 2 x 4 weights + 4 biases = 12. Hidden to output: 4 x 1 weights + 1 bias = 5. Total: 17 parameters.

Common mistakes to avoid

  • Forgetting to add the bias to the weighted sum
  • Thinking a neuron outputs the weighted sum directly, without an activation function
  • Expecting a single neuron to solve problems that are not linearly separable, like XOR
  • Using too high a learning rate so training becomes unstable
  • Believing a network that fits its training data will also do well on new data (overfitting)
  • Treating a network's prediction as a certainty instead of an estimate

Practice exercises

Weighted sum

A neuron has inputs x = (2, 3), weights w = (0.5, -1) and bias b = 1. Compute z.

Hint: Multiply each input by its weight, add them, then add the bias.

Show solution

z = 0.5 x 2 + (-1) x 3 + 1 = -1.

Choose the activation

Which activation function would you use for the output of a network that predicts a probability between 0 and 1, and why?

Hint: Think about the output range of each function.

Show solution

The sigmoid, because it outputs a value between 0 and 1 that can be read as a probability.

Count the parameters

A network has 3 inputs, two hidden layers of 5 neurons each and 2 output neurons. How many parameters does it have?

Hint: For each layer: inputs x neurons weights, plus one bias per neuron.

Show solution

Layer 1: 3x5 + 5 = 20. Layer 2: 5x5 + 5 = 30. Output: 5x2 + 2 = 12. Total: 62.

Key takeaways

  • An artificial neuron multiplies inputs by weights, adds a bias and applies an activation function
  • Hidden layers let a network solve problems, such as XOR, that a single neuron cannot