How calculators work

A calculator looks simple: you press some keys and an answer appears. Behind the display, though, lies a clever chain of steps, and a history of counting tools that goes back thousands of years.

A pocket calculator with a green display showing 3.14159
A pocket calculator with a green display showing 3.14159

From key press to answer

Every key press becomes a token: a number, an operator, a bracket or a function. When you press =, the calculator reads the tokens in order, works out which operations must come first and then calculates the answer step by step. Inside the chip, numbers are stored in binary, which is why some decimals, such as 0.1, can only be stored approximately.

Order of operations

Mathematicians agree on a fixed order so that a sum means the same to everyone: brackets first, then powers and roots, then multiplication and division, and finally addition and subtraction. In English this is often remembered as BODMAS or PEMDAS. That is why 2 + 3 × 4 is 14: the multiplication comes before the addition. Simple calculators that work strictly from left to right give 20 instead.

Scientific functions

Functions such as sin, ln and √ are not stored in a giant table. The calculator works them out with series and clever algorithms that add up small steps until the answer is accurate enough. Many pocket calculators use a method called CORDIC, which needs only additions, subtractions and shifts of digits.

From abacus to slide rule

The abacus, with beads on rods or counters on lines, was used in Mesopotamia, China and Rome for thousands of years. In 1617 John Napier described his calculating rods, and his logarithms soon made the slide rule possible, which engineers used until the 1970s. In 1642 Blaise Pascal built the Pascaline, a machine with gears that could add and subtract.

The pocket calculator

Mechanical calculators filled offices in the nineteenth and early twentieth centuries. In the 1960s the first electronic desktop calculators appeared, and in the early 1970s chips became small and cheap enough for calculators that fit in a pocket. In 1972 the HP-35 became the first scientific pocket calculator, and within a few years the slide rule had all but disappeared.

Frequently asked questions

Why does 0.1 + 0.2 sometimes give 0.30000000000000004?

Computers store numbers in binary, and 0.1 cannot be written exactly in binary. The tiny error shows up far behind the decimal point. This calculator rounds to 12 significant digits, so you see 0.3.

Why do some calculators give 20 for 2 + 3 × 4?

Simple calculators work out each step as soon as you press the next operator, from left to right. Scientific calculators, including this one, follow the order of operations and give 14.

What is the factorial of a number?

The factorial n! is the product of all whole numbers from 1 to n, so 5! = 1 × 2 × 3 × 4 × 5 = 120. By definition 0! = 1.

Ready to try it?

Open PictorX in your browser — no install, no credit card required to start.

Try the Calculator