How does a calculator work?

Open a pocket calculator and you find rubber keys with carbon pills, a circuit board with a grid of pads, one chip under a blob of black epoxy, an LCD, and a solar cell with a button cell for backup.

Press 7 and a chip scans a grid of wires, waits out the bounce and stores 0111. Build the adder from real logic gates, watch the carry ripple, and see why 1 ÷ 3 × 3 can come out as 0.9999999.

CalculatorClearOpened 16 Sept 202614 min to playFree · no sign-up

In 60 seconds

  1. A handful of parts

    Open a pocket calculator and you find rubber keys with carbon pills, a circuit board with a grid of pads, one chip under a blob of black epoxy, an LCD, and a solar cell with a button cell for backup. Everything clever happens inside the chip.

  2. Keys become bits

    The 20 keys sit where 5 row wires cross 4 column wires. The chip powers one row at a time and listens on the columns. It waits out the few milliseconds of contact bounce, then stores the digit in 4 bits of binary-coded decimal: 7 is 0111.

  3. Switches that decide

    Transistors are switches worked by electricity. A few of them make a logic gate: NOT flips a bit, AND needs both inputs, OR needs either, XOR needs them different. In CMOS a NOT gate is just 2 transistors, one pulling up to 1 and one pulling down to 0.

  4. Adding is XOR and AND

    The sum bit of two bits is XOR and the carry is AND. Five gates make a full adder, and four in a row add 4-bit numbers while the carry ripples through, 2 gate delays per bit. Flip B and add 1 and the same adder subtracts; shift and add, and it multiplies.

  5. Seven bars of liquid crystal

    A decoder turns each 4-bit digit into 7 segment signals. In each segment, liquid crystal twists light 90° between crossed polarisers so it looks pale. About 3 volts stands the molecules up, the twist is lost and the segment goes dark.

  6. Microwatts and the last digit

    CMOS and LCDs need so little power that a stamp-sized solar cell in room light runs the calculator. With only 8 digits, 1 ÷ 3 × 3 gives 0.9999999. Scientific calculators hide guard digits, and many find sin and cos with CORDIC: shifts and adds.

The history

4,000 years from pebbles on a board to a solar-powered chip in every school bag.

Read the full history
  1. 190The Chinese bead abacus
  2. 1642The Pascaline
  3. 1851The arithmometer goes on sale
  4. 1961ANITA, the first all-electronic desktop calculator
  5. 1971Busicom and the first microprocessor
  6. 1978Calculators that run on light

The full explanation

CalculatorClear, chapter by chapter

Chapter 1

Inside a pocket calculator

Twenty rubber keys, one chip, one display and a solar cell the size of a stamp.

A pocket calculator looks simple, and it is: open one and you find only a handful of parts.

Each key sits on a soft rubber dome. Inside every dome is a black carbon pill. Press a key, the dome squashes, and the pill touches two comb-shaped copper pads on the circuit board, joining them. That's the whole switch.

The pads are wired in a grid of rows and columns, the key matrix. A single chip checks the grid hundreds of times a second to find which key is down. On cheap calculators the chip is glued straight onto the board and covered with a blob of black epoxy.

The chip does all the maths in binary, using thousands of tiny switches called transistors, then lights the digits on the LCD. Pink rubber zebra strips carry the signals to the glass. A strip of solar cell and a tiny button cell power the lot, using about a ten-thousandth of a watt (see chapter 6).

In the next chapters you'll follow one sum all the way: key press, binary, logic gates, the adder and the display. A computer does exactly the same, only much more of it (see ComputerClear, coming soon).

Try “Inside a calculator” in the interactive model →

Chapter 2

From a key press to binary

The chip scans a grid of wires to find your key, waits out the bounce, and stores the digit as 4 bits.

Your calculator has 20 keys but the chip doesn't have 20 wires for them. The keys sit where 5 row wires cross 4 column wires: the key matrix.

The chip scans it. It puts a voltage on row 1 and listens on every column. Nothing? It moves on to row 2, then row 3, and so on, round and round, hundreds of times a second. When a pressed key joins row 3 to column 2, the chip hears the column go high while row 3 is on, and it knows exactly which key it is.

There's a snag. Metal contacts bounce: for a few thousandths of a second they touch, spring apart and touch again. Read too eagerly and one press looks like five. So the chip debounces: it waits until the signal has stayed steady for about 10 to 20 milliseconds.

Then the digit becomes binary. Calculators usually keep each decimal digit in its own 4 bits, called BCD (binary-coded decimal): 7 is 0111, so 47 is 0100 0111. Pure binary would be 101111. BCD wastes a few bit patterns but makes showing digits easy.

Try “Keys to numbers” in the interactive model →

Chapter 3

Switches that make decisions

A transistor is a switch worked by electricity. Wire a few together and you get gates: NOT, AND, OR, XOR.

Everything a calculator does comes down to one tiny part: the transistor. Think of it as a switch with no finger: a voltage on its gate turns it on or off. A calculator chip has thousands of them; a phone chip has billions.

Wire a few transistors together and you get a logic gate, which looks at 1s and 0s and answers with a 1 or a 0:

NOT flips its input. AND gives 1 only if both inputs are 1. OR gives 1 if either is. XOR ("exclusive or") gives 1 if the inputs are different. A truth table lists every answer.

Look inside (switch to "Inside: CMOS"). Modern chips use CMOS: pairs of opposite transistors. A PMOS switch closes when its input is 0 and connects the output to the supply (1). An NMOS switch closes when its input is 1 and connects the output to ground (0). One of each makes a NOT gate with just 2 transistors. Because one switch is always open, almost no current flows when nothing changes. That's why a calculator can run on a scrap of solar cell (chapter 6).

George Boole wrote down this logic in 1854. In 1937 Claude Shannon showed switches could do it, and every computer since has been built from gates (see CurrentClear for circuits, and ComputerClear, coming soon).

Try “Logic gates” in the interactive model →

Chapter 4

Adding with logic gates

Two gates add two bits. Five add three. Chain four and the carry ripples from bit to bit.

Add two bits and there are only four cases: 0+0 = 0, 0+1 = 1, 1+0 = 1 and 1+1 = 10 (that's 2 in binary: write 0, carry 1). Look closely: the written digit is just XOR and the carry is just AND. Two gates make a half adder.

For longer numbers each column must also add the carry coming in from the right. That's a full adder: two XORs, two ANDs and an OR, 5 gates.

Line up four full adders and you can add two 4-bit numbers (0 to 15). The carry out of each bit feeds the next: a ripple-carry adder. It is slow in one way: the top bit can't be sure of its answer until the carry has rippled through every bit, 2 gate delays per bit.

Subtracting uses the same adder. To do A − B, flip every bit of B (an XOR per bit does it) and add 1 through the first carry. This trick is called two's complement. Multiplying is shift and add: for each 1 in B, add a copy of A shifted left. Your calculator does exactly this, one decimal digit at a time.

Try “Adding” in the interactive model →

Chapter 5

Seven segments of liquid crystal

A digit is seven bars. Each bar is a sandwich that twists light, until a small voltage stops the twist.

Every digit on the calculator is made of just seven bars, segments a to g. Light the right ones and you get any digit from 0 to 9.

The chip holds each digit as 4 bits of BCD (chapter 2). A small circuit called a decoder turns those 4 bits into 7 on/off signals, one per segment. For example segment a is on for 0, 2, 3, 5, 6, 7, 8 and 9. The truth table below lists all of them.

How does a segment go dark? It's a sandwich (on the left). Light passes a polariser, which lets through only light vibrating one way. Between two glass plates, rod-shaped liquid crystal molecules are arranged in a gentle quarter-turn twist. The light follows the twist, turns 90°, and slips through the second polariser, which is turned 90° too. A mirror behind sends it back out: the segment looks pale, like the background.

Put about 3 volts across a segment and the molecules stand up along the electric field. No twist, so the light isn't turned, and the second polariser blocks it: the segment goes dark. No light is made at all, which is why an LCD needs so little power. TVs use the same trick with a backlight and colour filters (see TVClear).

Try “The display” in the interactive model →

Chapter 6

Sunlight, and the last digit

Why a stamp-sized solar cell is enough, why 1 ÷ 3 × 3 isn't always 1, and how sin and cos come from adding.

Power. A CMOS chip only uses energy when its gates switch (chapter 3), and the LCD makes no light of its own (chapter 5). So a simple calculator gets by on tens of microwatts: millionths of a watt. Casio lists 100 µW for a scientific model. A little amorphous silicon solar cell in room light makes about that much. The first LED calculators needed hundreds of times more: the 1972 Sinclair Executive used 20 mW.

Precision. A basic calculator has 8 digits and simply cuts off the rest. So 1 ÷ 3 = 0.3333333, and × 3 gives 0.9999999, not 1. That's fixed point: the decimal point sits somewhere in 8 digit places. Scientific calculators use floating point: digits plus a power of ten, like 6.02 × 10²³, and they keep a few hidden guard digits so answers like this round back to 1.

Computers use binary floating point, which can't store 0.1 exactly, so 0.1 + 0.2 comes out as 0.30000000000000004. Mostly harmless. But in 1994 the Pentium FDIV bug, a few missing entries in a table inside Intel's chip, made some divisions wrong in the fifth digit, and it cost Intel $475 million.

sin and cos. Scientific calculators don't store tables of sines. Many use CORDIC (1959): turn an arrow towards the angle you want in smaller and smaller steps, each one an angle whose tangent is ½, ¼, ⅛ … Each step needs only a shift and an add, exactly what the adder in chapter 4 can do. After 16 steps you have about 5 correct digits.

Try “Power and precision” in the interactive model →

Test yourself

Frequently asked

What actually closes the circuit when you press a calculator key?

A carbon pill inside a rubber dome touching two pads. The dome squashes and its carbon pill bridges two comb-shaped pads on the board.

Why are the keys wired in rows and columns?

So a few wires can serve many keys. 5 rows + 4 columns is 9 wires for 20 keys. The chip finds a key by where its row and column meet.

What is the black blob on a cheap calculator's board?

Epoxy covering the bare chip. The bare silicon chip is bonded straight to the board and sealed under epoxy. It is the whole brain.

How does the chip know which key in the grid is pressed?

It turns on one row at a time and sees which column answers. Only the pressed key joins its row to its column, so the column goes high exactly when that row is on.

Why does a calculator debounce its keys?

Contacts bounce, so one press could count as several. For a few milliseconds the contact flickers on and off. Waiting until it is steady turns that into one clean press.

What is 9 in BCD?

1001. 9 = 8 + 1, so the 8 and 1 bits are on: 1001.

An AND gate has inputs 1 and 0. What is its output?

0. AND gives 1 only when both inputs are 1.

Which gate gives 1 when its two inputs are different?

XOR. XOR: 0 and 1, or 1 and 0, give 1. Two equal inputs give 0.

In a CMOS NOT gate with input 1, which transistor conducts?

The NMOS, pulling the output to 0. A 1 on the input closes the NMOS switch to ground and opens the PMOS, so the output is 0.

In binary, what is 1 + 1?

10 (write 0, carry 1). Binary has only 0 and 1, so 1 + 1 = 10: a 0 in this column and a carry of 1.

Which two gates make a half adder?

XOR for the sum, AND for the carry. The sum bit is 1 when exactly one input is 1 (XOR). The carry is 1 only when both are (AND).

How does the adder subtract A − B?

It flips B's bits and adds 1 (two's complement). Adding the flipped B plus 1 is the same as subtracting B, so one adder does both.

How many segments make a calculator digit?

7. Seven bars, a to g, are enough to draw 0 to 9 (plus a separate decimal point).

What makes an LCD segment look dark?

A voltage stops the twist, so the second polariser blocks the light. Without the 90° twist the light keeps its direction and the crossed polariser stops it.

What does the decoder do?

Turns 4 BCD bits into 7 segment signals. It is a small block of logic gates with 4 inputs and 7 outputs, following the truth table.

Why can a small solar cell run a calculator?

CMOS chips and LCDs need only millionths of a watt. CMOS gates draw current only when they switch, and an LCD makes no light, so tens of microwatts are enough.

An 8-digit calculator shows 1 ÷ 3 × 3 = 0.9999999. Why?

1 ÷ 3 was cut to 0.3333333, and the lost bit never comes back. With only 8 digits, the endless 3s are cut off. Scientific calculators hide extra guard digits to avoid this.

What operations does each CORDIC step need?

Only a shift and an add. Multiplying by ½, ¼, ⅛… is just shifting bits, so each step is shifts and adds.

Words worth knowing

Key matrix
Keys wired where rows cross columns, so a few wires can serve many keys.
Debouncing
Ignoring a switch until its flickering contact has settled.
BCD
Binary-coded decimal: each decimal digit kept in its own 4 bits.
Transistor
A switch with no moving parts, turned on and off by a voltage.
Logic gate
A small circuit that turns input bits into an output bit by a fixed rule, like AND or XOR.
Full adder
Five gates that add two bits and an incoming carry.
Two's complement
Subtracting by adding: flip every bit of the number and add 1.
Seven-segment display
Seven bars that together can draw any digit from 0 to 9.
CORDIC
A way to compute sin and cos by turning in shrinking steps, using only shifts and adds.

Fork it. Teach with it.

This box is plain HTML, CSS and JavaScript, with no build step and no accounts. Run it yourself and it sends nothing anywhere. The code is MIT. The words, images and videos are CC BY 4.0, so you can reuse them anywhere if you credit “Glassbox, glassbox.how/e/calculatorclear”.

git clone https://github.com/bdeeps/calculatorclear.git

Built with three.js (MIT), Geist, Instrument Serif (SIL OFL 1.1).

←→ previous / next box · / search

Would you like to see the full page, with the interactive model?