From electricity to bits
Lesson 1 of 4
1From electricity to bits
No background needed here. We start from a lamp and a switch and reach the letter you are reading on your screen right now.
Map of this part
The concepts in order, click any one to jump to it:
Two ways into the same idea
Picture a panel with a row of light switches. Each switch is either off or on, nothing in between. If we write off as 0 and on as 1, we can agree that one pattern of lights means the letter "A" and another means the colour red. A computer is a panel with billions of these switches.
A transistor is an electronic switch that holds one bit (0 or 1). Eight bits make a byte with 256 possible values. All data is binary numbers, and what a number means is set by an agreed encoding: UTF-8 for text, RGB for colours, formats like PNG for images.
Before You Start
🔌You have used a light switch
You know a switch either lets current through or cuts it. That is all we need.
🔢Counting to ten
We will count in a slightly different way, but the idea is still counting.
The Core Idea
1The switch: open or closed
Look at the picture. A switch lets current reach a lamp or cuts it off. Two states only: lit or not lit.
Inside a processor there are billions of these switches, but they are tiny and opened and closed by electricity itself, not by a finger. They are called transistors.
Engineers agreed to name the two states with two digits: current flowing is 1, no current is 0. All of programming starts here.
2Bits and bytes
One slot holding a 0 or a 1 is a bit. One bit tells two things apart. Two bits tell four apart. Three bits, eight.
Follow the picture: three slots count from 0 to 7 the way you normally count, except a slot fills up at 2 instead of 10. That is binary.
Eight bits together are a byte, and a byte tells 256 things apart. That is enough to give every key on a keyboard its own number.
3From numbers to letters and pictures
A computer does not know the letter A. It knows that the number 65 was agreed to mean A. Arabic letters have larger numbers in a wider table called Unicode.
A picture is a grid of dots, and each dot is three numbers: how much red, how much green, how much blue. Sound is a stream of numbers measuring a wave thousands of times a second.
The one rule to take from this lesson: everything in a computer is numbers, every number is bits, and every bit is a switch.
How It Works, Step by Step: How a letter you type becomes light on the screen
You press A, and the keyboard sends the number 65 as eight electrical pulses: 01000001.
The computer keeps those bits in memory as charges in tiny switches.
To display it, it looks up the shape of character 65 in the chosen font, itself a set of numbers describing dots.
The screen lights the required dots in their colours, and you see an A. Along the whole way there was nothing but numbers.
Try it without code
Myth vs Reality
| Myth | Reality |
|---|---|
| A computer "understands" letters and pictures. | It understands only 0 and 1. The understanding lives in agreements people made: this number means this letter. |
| A bit is a physical thing you can see. | A bit is a state: a switch closed or open, a charge present or not. What you see is its effect. |
| Binary is harder than decimal. | It is the same counting with two digits instead of ten. The difficulty is only unfamiliarity. |
Try it yourself
How many different things can four bits tell apart?
Each bit doubles the possibilities: one bit 2, two bits 4, three 8, four 16. A full byte of eight bits reaches 256.
Quick review cards
Check Your Understanding
Why not build computers on ten states instead of two?
Because telling two electrical states apart (current or none) is easier and less error-prone than telling ten levels of current apart.
What changes if a byte were six bits instead of eight?
It would tell only 64 values apart, not enough for upper and lower case letters, digits and symbols together.
If A is 65, what is B most likely?
66. Consecutive letters took consecutive numbers in the table.
Resources for this lesson
Grouped by type. Start with the official docs for precision, or an article or video for the explanation.
Done with this lesson?
Sign in to save your progress.