A Decision You Make Without Writing It Down
It is 4 PM and you are standing at your window. Your friends are messaging you: "Cricket, ground, now?" Before you reply, your brain does something remarkable in under a second. It checks the sky — is it raining? It checks your bag — is the homework done? It checks the group chat — do enough friends actually want to play? Then, somehow, all three checks combine into one output: "yes, I'm coming" or "no, not today."
Notice what just happened. You did not apply one single rule like "if raining, never play." Rain alone might not stop you if your homework is done and everyone is waiting. But rain combined with unfinished homework probably will. Your brain is weighing several pieces of evidence against each other and firing a decision only when the combined evidence crosses some internal tipping point. That single sentence — evidence gets weighed, and a decision fires only past a tipping point — is the entire idea behind a neural network. Everything else in this chapter is just turning that sentence into arithmetic a computer can run.
What Is Actually Happening Inside a Real Neuron
Your brain contains roughly 86 billion neurons, each one a tiny biological cell, and each connected to thousands of other neurons. A single neuron has three working parts. Dendrites are branch-like extensions that receive incoming electrical signals from other neurons. The soma (cell body) collects and adds up all the signals arriving through the dendrites at that instant. If — and only if — that combined signal crosses a certain voltage threshold, the neuron "fires": it sends a sharp electrical pulse down a long fibre called the axon, which branches out at its end and passes the signal on to the next set of neurons across tiny gaps called synapses.
Two details matter enormously for what comes next. First, not every incoming connection matters equally — some synapses are strong (a small nudge sends a big signal through) and some are weak (barely any signal gets through). Second, the neuron does not react gradually — it stays silent until the summed signal crosses the threshold, and only then does it fire. A neuron 1% below threshold does nothing at all; it is not "10% activated." This all-or-nothing, threshold-crossing behaviour is exactly what we will now build in code.
The Artificial Neuron: Turning Biology Into Arithmetic
An artificial neuron (also called a perceptron, a term coined by Frank Rosenblatt in 1958) copies this structure using only numbers:
- Each dendrite becomes an input, written x1, x2, x3, ... — usually a number representing some piece of evidence.
- Each synapse's strength becomes a weight, written w1, w2, w3, ... — a number that says how much that particular input should count.
- The soma's job of adding everything up becomes a weighted sum: multiply every input by its own weight, then add all the products together.
- There is also one extra number called the bias, which shifts how easy or hard it is to cross the threshold overall — think of it as how "eager" or "reluctant" the neuron is by default, before any evidence arrives.
- The threshold-crossing fire-or-don't-fire behaviour becomes an activation function. The simplest one, called the step function, outputs 1 if the weighted sum (plus bias) is 0 or more, and outputs 0 otherwise.
Written as one formula, with n inputs:
weighted sum = (x1 × w1) + (x2 × w2) + ... + (xn × wn) + bias
output = 1 if weighted sum >= 0
output = 0 if weighted sum < 0
That's the whole model. No calculus, no magic — just multiply, add, and compare to zero.
Worked Example: Should I Play Cricket Today?
Let's build a real neuron for the window-decision from the start of this chapter, using three inputs, each either 0 (no) or 1 (yes):
- x1 = is it raining right now
- x2 = is my homework finished
- x3 = do my friends want to play
Now we choose weights that reflect how much each factor should matter. Rain should matter a lot and push the decision toward "no," so we give it a large negative weight. Homework and friends both push toward "yes," so they get positive weights:
w1 = -5 (rain: strongly discourages playing)
w2 = 2 (homework done: encourages playing)
w3 = 3 (friends want to play: encourages playing)
bias = -4 (by default, slightly reluctant to play)
Let's trace three real days by hand before writing any code, because you should be able to predict a neuron's output with pen and paper — that is the skill this chapter is really testing.
Day 1 — no rain, homework done, friends want to play: x1=0, x2=1, x3=1.
weighted sum = (0 × -5) + (1 × 2) + (1 × 3) + (-4) = 0 + 2 + 3 - 4 = 1. Since 1 >= 0, output = 1 (go play).
Day 2 — raining, homework done, friends want to play: x1=1, x2=1, x3=1.
weighted sum = (1 × -5) + (1 × 2) + (1 × 3) + (-4) = -5 + 2 + 3 - 4 = -4. Since -4 < 0, output = 0 (stay in). Notice how the huge -5 for rain overpowered two positive votes — that is exactly why we gave rain a bigger weight than the others.
Day 3 — no rain, homework NOT done, friends want to play: x1=0, x2=0, x3=1.
weighted sum = (0 × -5) + (0 × 2) + (1 × 3) + (-4) = 0 + 0 + 3 - 4 = -1. Since -1 < 0, output = 0 (stay in). One vote of support from friends alone isn't enough to overcome the -4 bias.
Coding the Neuron
Here is that exact neuron as a Python function, using the same numbers we just traced by hand:
def neuron(x1, x2, x3, w1, w2, w3, bias):
total = x1 * w1 + x2 * w2 + x3 * w3 + bias
if total >= 0:
return 1
else:
return 0
w1, w2, w3 = -5, 2, 3
bias = -4
print(neuron(0, 1, 1, w1, w2, w3, bias)) # Day 1: no rain, hw done, friends want to play
print(neuron(1, 1, 1, w1, w2, w3, bias)) # Day 2: raining, hw done, friends want to play
print(neuron(0, 0, 1, w1, w2, w3, bias)) # Day 3: no rain, hw NOT done, friends want to play
Trace it exactly as Python would run it. For Day 1: total = 0*(-5) + 1*2 + 1*3 + (-4) = 0 + 2 + 3 - 4 = 1, and since 1 is not less than 0, the function returns 1. For Day 2: total = 1*(-5) + 1*2 + 1*3 + (-4) = -5 + 2 + 3 - 4 = -4, which returns 0. For Day 3: total = 0 + 0 + 3 - 4 = -1, which returns 0. Running this program prints exactly:
1
0
0
which matches our hand calculation exactly. This match is not a coincidence — it is the entire point. A neuron is not a mysterious black box; it is a small, fully traceable arithmetic recipe. Anyone who can multiply, add, and compare two numbers can compute a neuron's output by hand, exactly as we just did.
Common Misconception: "Neural Networks Are Basically Tiny Digital Brains"
This is a natural conclusion to draw from everything above, and it is wrong in an important way. A real biological neuron is not a simple weighted sum. Its firing depends on precise timing (not just totals), it can have anywhere from a few hundred to over ten thousand synaptic connections, its synapses change strength continuously through learning and even through chemicals like dopamine, and different neurons behave in electrically different ways. The artificial neuron in this chapter — multiply, add, compare to zero — is a deliberately extreme simplification, "inspired by" biology in the same loose sense that an airplane is "inspired by" a bird: both fly, but a wing is not a feather, and a weighted sum is not a living cell. Whenever you read "neural network," mentally translate it to "a system built from many small weighted-sum-and-threshold units," not "an artificial brain."
A second, closely related misconception: in our cricket example, we chose the weights (-5, 2, 3) and the bias (-4) by reasoning about what made sense. It is tempting to assume that is how all neural networks work — a human sits down and hand-picks every number. For a single toy neuron with three inputs, hand-picking works fine. But real neural networks used for tasks like recognising handwritten Devanagari or English digits, or filtering spam, can have millions of weights — far too many for any person to choose by hand. Instead, those weights are found automatically by a training process: the network is shown many examples with known correct answers, and an algorithm (you will meet its name, gradient descent, in a later chapter) nudges every weight, a tiny bit at a time, so the network's outputs get closer to the correct answers. The arithmetic you traced by hand in this chapter — weighted sum, then threshold — is exactly what runs after training is done; training is simply the separate process that discovers good values for w1, w2, w3, and bias instead of a human guessing them.
One Neuron Isn't Always Enough: The Two-Way Switch Problem
Many Indian homes have a staircase light controlled by two switches — one at the bottom of the stairs, one at the top — wired so that flipping either switch changes the light. Think about the pattern: if both switches are in the same position (both up or both down), the light is OFF. If the switches are in different positions (one up, one down), the light is ON. Let's write this as a table, using 0 and 1 for the two switch positions and treating "light ON" as output 1:
switch A switch B light
0 0 0
0 1 1
1 0 1
1 1 0
This pattern is called XOR (exclusive OR): the output is 1 exactly when the two inputs differ. Can a single neuron like the one we built compute this? Let's actually try. We need weights wA, wB and a bias such that the weighted sum is negative for (0,0) and (1,1), but non-negative for (0,1) and (1,0).
Here is why no choice of wA, wB, bias can ever satisfy all four rows at once — and you can see it geometrically without any algebra. Plot the four input pairs on a grid with switch A on the horizontal axis and switch B on the vertical axis. A single neuron's weighted sum, compared to zero, is a straight line cutting the grid into two halves — everything on one side outputs 1, everything on the other outputs 0. That is all a single neuron can ever do: draw one straight line and separate the plane into two regions.
Look at where the ON points and OFF points sit: (0,1) and (1,0) — both ON — sit on opposite corners of the square, and (0,0) and (1,1) — both OFF — sit on the other two opposite corners. Any straight line you draw across this square will always have one ON point and one OFF point together on the same side, because the two ON points and two OFF points alternate around the square rather than clustering on one side of any line. Try the horizontal line and the vertical line shown above — each one groups a green (ON) point with a red (OFF) point. This isn't a failure of imagination in choosing weights; it is a mathematical fact about this arrangement of points. A single neuron, no matter which weights you give it, can never compute XOR.
Stacking Neurons: How a Hidden Layer Solves It
If one straight line can't separate the points, what about two lines? That is exactly what adding a second layer of neurons gives us. Instead of connecting the inputs straight to one output neuron, we first pass them through two neurons in a middle layer — called a hidden layer because it sits between the input and the output — and only then combine their outputs into a final decision.
Here is a hand-built (not yet trained) three-neuron network that solves XOR exactly:
- h1 computes OR: weights (1, 1), bias -0.5. So h1 = 1 whenever at least one switch is 1.
- h2 computes AND: weights (1, 1), bias -1.5. So h2 = 1 only when both switches are 1.
- output combines them: weights (1, -1) applied to (h1, h2), bias -0.5. This fires only when h1 is 1 and h2 is 0 — in other words, "at least one switch is on, but not both."
That final condition — "at least one, but not both" — is precisely the XOR rule. Let's verify it in code and trace all four cases:
def step(total):
return 1 if total >= 0 else 0
def two_way_switch(x1, x2):
h1 = step(x1 * 1 + x2 * 1 - 0.5) # OR neuron
h2 = step(x1 * 1 + x2 * 1 - 1.5) # AND neuron
output = step(h1 * 1 + h2 * -1 - 0.5) # combine: h1 minus h2
return output
for x1 in [0, 1]:
for x2 in [0, 1]:
print(x1, x2, "->", two_way_switch(x1, x2))
Trace (0, 0): h1 = step(0+0-0.5) = step(-0.5) = 0. h2 = step(0+0-1.5) = step(-1.5) = 0. output = step(0*1 + 0*-1 - 0.5) = step(-0.5) = 0. Correct — both switches down, light off.
Trace (0, 1): h1 = step(0+1-0.5) = step(0.5) = 1. h2 = step(0+1-1.5) = step(-0.5) = 0. output = step(1*1 + 0*-1 - 0.5) = step(0.5) = 1. Correct — light on.
Trace (1, 0): by the same arithmetic with x1 and x2 swapped, h1 = 1, h2 = 0, output = step(0.5) = 1. Correct — light on.
Trace (1, 1): h1 = step(1+1-0.5) = step(1.5) = 1. h2 = step(1+1-1.5) = step(0.5) = 1. output = step(1*1 + 1*-1 - 0.5) = step(1-1-0.5) = step(-0.5) = 0. Correct — both switches up, light off.
Running the program prints exactly:
0 0 -> 0
0 1 -> 1
1 0 -> 1
1 1 -> 0
— the complete, correct XOR table, produced by three neurons that individually could only draw straight lines, but together carve the plane into the diagonal pattern that one line alone could never make. This is the real reason "deep" networks (networks with hidden layers) exist: stacking simple threshold units lets the network represent far more complicated boundaries than any single unit could, one layer building on what the previous layer already separated.
From Hand-Picked Numbers to a Real Network
Everything in this chapter used weights and biases that we chose ourselves by reasoning about the problem. That was deliberate — it let you trace every single number by hand and see exactly why the network produces the output it does, with nothing hidden. A real neural network used for something like classifying a UPI transaction as genuine or suspicious works on the identical arithmetic: inputs might be the transaction amount, how far the payment location is from your usual city, and how unusual the time of day is; each gets a weight; the weighted sum plus bias goes through an activation function; the output is a decision. The only real difference is scale and origin of the numbers — such a system may have dozens of inputs feeding through several hidden layers of neurons, and every one of those weights was learned automatically from millions of past transactions rather than picked by a person. The step function itself is also usually swapped for smoother activation functions (you will meet ones called sigmoid and ReLU later) so that the network can express "somewhat confident" rather than only a hard 0 or 1 — but the core skeleton, weighted sum then activation, is unchanged from the neuron you traced by hand today.
Quick Recap
- A biological neuron receives signals through dendrites, sums them in the soma, and fires an all-or-nothing pulse down the axon only once the sum crosses a threshold.
- An artificial neuron copies this with arithmetic: multiply each input xi by its weight wi, add all the products plus a bias, then apply an activation function (the step function outputs 1 if the total is ≥ 0, else 0).
- Weights control how much each input matters; bias shifts how easily the neuron fires overall; in a hand-built toy example we choose these numbers, but in real systems they are learned from data through training.
- A single neuron can only separate its inputs with one straight line (or straight boundary), so it can compute patterns like AND and OR but cannot compute XOR, where the "1" outputs and "0" outputs sit on opposite diagonals.
- Adding a hidden layer of neurons — each drawing its own line, then combined by a further neuron — lets the network represent far more complex patterns than any single neuron could, which is why "deep" (multi-layer) networks are more powerful than a single perceptron.
Test Yourself
- A neuron has inputs x1=1, x2=0, x3=1 with weights w1=4, w2=-2, w3=1 and bias=-3, using the step function. Compute the weighted sum by hand and state the output.
- Using the cricket neuron from this chapter (w1=-5, w2=2, w3=3, bias=-4), find one combination of x1, x2, x3 (each 0 or 1) that we have not already traced, and compute its output by hand.
- Explain, using the diagonal-points idea from this chapter, why no single neuron can compute XOR — do not just say "it's impossible," explain why using the geometry of the four points.
- In the hidden-layer XOR network, what does h1 alone compute, and what does h2 alone compute? Why does combining them with weights (1, -1) and bias -0.5 produce XOR rather than OR or AND?
- A classmate says, "A bigger neural network is basically a bigger, faster brain." Identify what is wrong with this statement, using at least one specific difference between biological and artificial neurons from this chapter.
- CBSE-style MCQ: In an artificial neuron using the step activation function, if the weighted sum (including bias) equals exactly 0, the output is: (a) (b) 0 (c) 1 (d) depends on the number of inputs. Justify your choice using the definition given in this chapter.
Practice Exercises
Now it is time to practice! Complete these challenges to solidify your understanding:
- Exercise 1: Write a short program that demonstrates the core concept from this chapter. Test it with at least 3 different inputs.
- Exercise 2: Find a real-world example where introduction to neural networks: how brains inspire machines is used in an Indian company (like TCS, Infosys, Flipkart, or ISRO). Write a paragraph explaining the connection.
- Exercise 3: Create a mind-map connecting introduction to neural networks: how brains inspire machines to at least 3 other topics you have studied.