How a neural network recognises digits

Draw a digit and watch a real neural network work it out. See which neurons light up, what each of them looks for and how 784 pixels become one answer. It all runs in your browser.

Draw a digit

Or pick a handwritten digit from MNIST:

The network says3100% sure

Of 10,000 test digits it never saw while learning, it gets 97.8% right.

Inside the network

Go through the four steps, or click any neuron to see how it calculates.

PictureLayer 1 · 32Layer 2 · 16Answer00%10%20%3100%40%50%60%70%80%90%
  • Stronger colour = the neuron shines more
  • Pushes the next sum up
  • Pushes the next sum down

Step 4: the output for the digit 3

Each of the 10 outputs adds up the 16 neurons of layer 2 in the same way. The higher an output’s sum, the more the network leans towards its digit.

What added and took away the most

Added+14.64
Took away-0.20
Bias+0.54
Sum14.97

The sum of this output is 14.97. Softmax turns it into a share of 100% (see below).

The bias is the neuron’s own number, learned like the weights: it makes the neuron easier or harder to light up.

From 10 sums to one answer

Softmax turns the 10 sums into shares that add up to 100 %. The highest sum gets the largest share: if one sum is higher than another by 1, its share is about 2.7 times larger. The digit with the largest share is the answer. The share shows how strongly the network leans towards a digit, not how likely it is to be right.

DigitSumShare
0-5.370%
1-0.270%
22.320%
314.97100%
4-6.860%
54.380%
6-10.560%
71.130%
8-1.010%
91.460%

A demonstration for learning; nothing you draw leaves your browser. How it is calculated and where the data come from

How a neural network recognises a digit

A neural network is made of simple units called neurons, arranged in layers. Each neuron does just one thing: it adds up the numbers coming in, each multiplied by its own weight, adds its bias, and passes the result on if it is positive. The cleverness is not in any one neuron but in the weights.

This network gets your drawing as 784 numbers, one per pixel. Layer 1 has 32 neurons, and each reacts to a short stroke in a certain place, as you can see in their patterns. Layer 2 has 16 neurons that combine those strokes into larger parts. The 10 outputs, one per digit, add up layer 2, and the highest one wins.

Nobody set the weights by hand. At first they were random and the network guessed at random. Then it was shown 60,000 handwritten digits with the right answers, and after every small batch each weight was nudged in the direction that makes the error smaller (backpropagation and gradient descent). After 30 passes over all the digits, its roughly 26,000 weights settled into the patterns you see.

That is also why the network makes mistakes a person would not. It has learned what MNIST digits look like, not what a digit is. Draw a digit very thin, cut off or in an unusual style, and the sums may point the wrong way. Try it: draw a 4 with an open top, a 7 with a bar or a letter, and watch which neurons react.

The same building blocks, in much larger numbers and other arrangements, are inside the networks that recognise speech, translate text or write it. The principle stays the same: a great many weighted sums, with weights learned from examples.

Frequently asked questions

Is this a real neural network?

Yes. It is a small but complete network, trained on real handwritten digits, and it calculates in your browser exactly as the picture shows. Every number in the picture is the real value from the calculation.

Is my drawing sent anywhere?

No. The network runs in your browser. The drawing is kept only in your browser’s storage, so it is still there when you come back.

Why does it get my digit wrong?

It knows only digits that look like the MNIST ones: one digit, drawn in the middle, with lines of normal thickness. It has never seen your handwriting, and it cannot answer “I don’t know”. Try drawing the digit larger and more simply, or look at which neurons of layer 1 lit up and which outputs they pushed up.

How accurate is it?

On the 10,000 test digits of MNIST, which it did not see while learning, it is right in about 98 cases out of 100; the exact share is under the drawing area. Digits drawn with a mouse look different from pen strokes on paper, so with them it can do worse.

What is MNIST?

A collection of 70,000 handwritten digits put together by Yann LeCun, Corinna Cortes and Christopher Burges in the 1990s from American handwriting samples. It has long been the first thing new methods are tried on, a kind of “hello world” of machine learning.

Related articles

How it is calculated and where the data come from

How the result is calculated

  1. Your drawing is drawn again the way MNIST prepared its digits: the strokes with a pen about 3 pixels wide, scaled to fit a 20 × 20 box with their shape kept, and moved so that the centre of their ink lands in the middle of a 28 × 28 picture. Each pixel is a number from 0 to 1.
  2. The network has 784 inputs, 32 neurons in layer 1, 16 in layer 2 and 10 outputs. Every neuron adds up its inputs, each times its weight, plus its bias. In the two hidden layers a negative sum becomes 0 (ReLU); the 10 output sums go through softmax, which turns them into shares adding up to 100 %.
  3. We trained the network on the 60,000 training digits of MNIST: 30 passes of gradient descent with momentum on batches of 64 digits, each digit moved, turned, slanted and made thinner or thicker at random, so that the network also knows digits drawn with a mouse.
  4. The accuracy is measured on the 10,000 test digits of MNIST, which the network never saw while learning, with the same code and the same weights the page uses. The result is shown under the drawing area.
  5. The weights are stored with 8 bits each; the accuracy above is measured after that rounding. A neuron of a hidden layer is coloured as strongly as its value against a high value of its layer (the 95th percentile over the test digits).

Assumptions and limits

  • The network knows only the digits 0 to 9 and always answers one of them, even for a letter or a doodle, sometimes with a large share.
  • The MNIST digits were written by employees of the US Census Bureau and by American high school students. Other handwriting, such as a 1 with a long upstroke or a crossed 7, may be recognised worse.
  • It is a small network built to be easy to follow. The convolutional network described by LeCun et al. (1998) made mistakes on less than 1 % of the same test digits; networks used in practice today are much larger still.
  • The network does not remember earlier drawings and does not learn from yours.

The example digits are handwritten digits from the MNIST test set. The numbers in the picture of the network are the real values of the calculation, not examples of ours.

Data sources and the period they hold for

Every number a calculator starts with or computes from comes from one of the sources below. Series names are given as the publisher names them. Each row shows the period the data refer to and, where we record it, the day we downloaded them. Official data can be months old when they are published, so check the current figure before you decide.

Official
Published by a central bank, a statistical office, the European Union or another public body.
Research or industry data
A dataset of a university, an index provider, an industry association or a data vendor.
Reported
A figure of an official body that we know only from the press and did not check in the primary source. Treat it as approximate.
Example
A round number of ours, not a statistic. Replace it with your own.

Handwritten digits for training the network

SourcePeriodType
Yann LeCun, Corinna Cortes, Christopher J. C. BurgesThe MNIST database of handwritten digits: 60,000 training and 10,000 test images of 28 × 28 pixels, size-normalized to a 20 × 20 box and centered by the center of mass (files from the torchvision mirror, checked against its MD5 sums)
1998downloaded 2026-10-17Research or industry data
Y. LeCun, L. Bottou, Y. Bengio, P. HaffnerGradient-based learning applied to document recognition, Proceedings of the IEEE 86 (11), 2278–2324
1998Research or industry data

Methodology text last reviewed 2026-10-06. Data last downloaded 2026-10-17. How we work with data and sources