plaination Xplaining Tomorrow Today
How Neural Network Works with Example?
AI Jun 26, 2026 · 5 tags

How Neural Network Works with Example?

A clear, analogy-driven guide to neural networks — layers, weights, activation functions, and training — with a real-world example anyone can follow.

#neural-network#ai#model#deep-learning#training

The Restaurant That Teaches Itself

Imagine a restaurant where the chefs have never tasted a pizza — but they’re determined to make the perfect one. Every night, the head chef (your “model”) tastes whatever comes out of the oven, compares it to the ideal pizza stored in his recipe book, and adjusts the spice racks, oven temperatures, and dough thickness for tomorrow’s batch. After a few hundred nights, the pizza is basically Michelin-starred.

That’s a neural network in a nutshell: a system that learns by trial, error, and adjustment — except instead of chefs and ovens, it’s layers of mathematical functions processing data. Let’s break down how it actually works, with a concrete example.


What Is a Neural Network in the Context of AI?

A neural network is a computational model inspired (loosely) by the way biological brains process information. In AI, it’s a collection of interconnected nodes — called neurons or units — organized into layers. Data flows through these layers, gets transformed at each step, and eventually produces an output: a classification, a prediction, a generated word.

The key idea is that the network learns the right transformations by adjusting the strength of connections between neurons — those are called weights. When the output is wrong, the network looks backward through its layers, figures out which connections contributed most to the error, and tweaks them slightly. Repeat millions of times, and the network becomes surprisingly good at whatever task you trained it on.


How Does a Simple Neural Network Work?

Let’s build one piece at piece with a real example: teaching a network to recognize whether a photo contains a cat or a dog.

Layer 1: Input

The image gets fed into the network as a grid of pixel values. A 28×28 grayscale image becomes 784 input neurons — each one holding the brightness of one pixel. No intelligence yet; just raw numbers. Stacked tiers of translucent wooden rings, each slightly off

Layer 2: Hidden Layers (The “Brain”)

This is where the magic happens. The network typically has one or more hidden layers between input and output. Each neuron in a hidden layer does three things:

  1. Multiplies each incoming pixel value by a weight (a number representing how important that pixel is for its decision).
  2. Adds a bias (a baseline adjustment).
  3. Passes the result through an activation function (more on that below).

In a simple network, you might have one hidden layer with 16 neurons. Each neuron is looking for a different pattern — one might fire strongly when it sees curves (potential ear), another when it sees elongated shapes (potential snout).

Layer 3: Output

Two output neurons: one for “cat” and one for “dog.” After the hidden layers do their work, the output neurons produce two numbers between 0 and 1. If “cat” outputs 0.87 and “dog” outputs 0.13, the network is 87% confident it’s looking at a cat.


The Training Process: How It Learns

Before a neural network can do anything useful, it needs to be trained. Here’s the loop:

  1. Feed it labeled examples. Show it 10,000 photos of cats and dogs with the correct labels.
  2. Make a prediction. The network guesses “cat” or “dog” for each photo.
  3. Measure the error. Did it guess right? By how much was it wrong? This is calculated by a loss function — a single number representing total mistake magnitude.
  4. Adjust the weights. Using an algorithm called backpropagation, the network traces backward from the output to figure out which weights need to change and by how much. Then it nudges them in the right direction using gradient descent.
  5. Repeat. Do this thousands or millions of times, and the weights settle into a configuration that produces accurate predictions. A grid of sliding wooden blocks, each set to a different gap

The training data is usually split into three sets: training data (what the network learns from), validation data (what it checks against during training to avoid memorizing), and test data (what it’s evaluated on at the end, to see how it generalizes to new, unseen examples).


What Is an Activation Function?

Without activation functions, a neural network is just a series of linear multiplications — which could be collapsed into a single linear operation. The activation function introduces non-linearity, letting the network learn complex, curved decision boundaries instead of just straight lines.

Common activation functions:

  • ReLU (Rectified Linear Unit): Outputs the input directly if it’s positive; zero otherwise. Simple, fast, and the workhorse of modern networks.
  • Sigmoid: Squashes any value into the 0-to-1 range. Useful for binary output neurons.
  • Softmax: Converts a set of numbers into probabilities that add up to 1. The standard choice for multi-class output layers (like our cat-vs-dog example).
  • Tanh: Similar to sigmoid but ranges from -1 to 1.

Think of an activation function as a gatekeeper: it decides whether a neuron should “fire” and pass information forward, and how strongly.


What Does It Mean to Understand a Neural Network?

Understanding a neural network doesn’t mean memorizing every weight and activation value — that’s practically impossible for real-world models with billions of parameters. It means grasping the architecture at a conceptual level: A row of clear glass tubes with internal float valves, water

  • What data flows in and what comes out?
  • What transformations happen at each layer?
  • How does the network learn from its mistakes?
  • What could go wrong? (Overfitting is the big one — when the network memorizes training data instead of learning general patterns.)

If you can explain the cat-vs-dog example to a friend who’s never touched code, you understand neural networks better than most people in the industry.


Neural Networks and the Human Brain: A Note on the Analogy

The name “neural network” comes from the fact that these models were inspired by biological neurons in the 1940s. A biological neuron receives signals through its dendrites, processes them in the cell body, and fires an electrical pulse down its axon if the combined signal crosses a threshold.

But the analogy breaks down fast. Biological brains have hundreds of billions of neurons with complex, dynamic structures, self-repair capabilities, and feedback loops spanning every part of the body. A modern neural network has maybe millions of artificial neurons doing simple math. It’s the concept that was borrowed — not the machinery. Don’t let the name fool you into thinking these systems are anything like consciousness.


A Concrete End-to-End Example

Let’s walk through exactly what happens when you show a neural network a handwritten digit (the classic MNIST dataset example): Hands turning brass dials on a series of connected glass tub

  1. Input: A 28×28 pixel image of the digit “7” enters as 784 numbers.
  2. Hidden layer 1 (32 neurons): Each neuron computes a weighted sum of the 784 pixels, adds a bias, and applies ReLU. The network learns that certain pixels in the top-right corner are important for recognizing vertical strokes.
  3. Hidden layer 2 (16 neurons): These neurons combine the features from layer 1. Some might activate for horizontal lines, others for curves.
  4. Output layer (10 neurons): One for each digit 0–9. The “7” neuron outputs 0.94, and the nearest competitor (“1”) outputs 0.04. The network correctly identifies the digit.
  5. If it was wrong: Backpropagation would trace the error back through all the layers and adjust the weights so the next time a similar “7” appears, the “7” neuron fires more confidently.

Quick Quiz: Test Your Understanding

Q1: What role do activation functions play in a neural network? A: They introduce non-linearity, allowing the network to learn complex patterns. Without them, the network could only model linear relationships.

Q2: What happens during backpropagation? A: The network calculates how much each weight contributed to the prediction error and adjusts them in the direction that reduces that error — working backward from output to input layers.

Q3: What is the difference between training, validation, and test data? A: Training data teaches the network, validation data helps tune hyperparameters and catch overfitting during training, and test data provides an unbiased final evaluation of how well the network generalizes.


Sources

Watch the full lesson