Difference Engine No. 2 · The story · Dark · 3D view

4,782,969 + 5,217,031 = 10,000,000That sum is a carry. Watch it run.

Babbage's Difference Engine No. 2, working in your browser

Three cycles of the logarithm table, glowing.

Eight columns of thirty-one figure wheels, exact to the last digit. Turn the crank, set it to a table of logarithms, and watch 1849 compute.

Open the 3D view
Post on X Share on LinkedIn

Look

The engine

The whole machine, running: the columns of wheels on the right, the printer on the left.

Hover or drag the crank to turn it; press a wheel to set a digit by hand.

0128901239012894567801234067892345634567001223344556778899LINE0000000000000000000000000000000000000000000000000000000000000000122334455677889901289
Wheels turning nowFigure wheels, 8 × 31Sector gears between columnsThe printerPalette
What the marks mean
  • The wheels being turned: a receiving column counting up while its giver counts down, or the one wheel taking a carry
  • Figure wheels, 8 columns × 31, digits 0–9 round each rim, read against the index bar; a tab at 9 → 0 warns the carry lever behind
  • Sector gears between the columns; a column rises or drops into mesh, so one sector column serves each addition
  • The printer: copy sectors and racks take column f off in turn 3 to a row of 31 type wheels; the platen prints the checking copy on the paper web behind, the anvil impresses the stereotype tray in front

Follow

How it computes

One row of the table is four turns of the crank.

Turn 1

Half the columns add into their neighbours.

Turn 2

A sweep climbs the receiving columns and settles the carries.

A carry climbing through four nines, slowed six times.

More on the four turns

One cycle of the engine is one turn of the main shaft, four turns of the crank through the 4:1 gear, and it produces one row of the table. Press Show me and the figure poses at the middle of that turn, in whatever cycle it is in now; the readout in the card's corner says where it is.

Turn 1

Odd into even: Δ1 → f, Δ3 → Δ2, Δ5 → Δ4, Δ7 → Δ6. Each giving column counts down to zero while the sector gears beside it turn the receiving column up by the same amount. Nothing carries yet: a wheel that passes 9 → 0 only warns the carry lever behind it.

Turn 2

On f, Δ2, Δ4 and Δ6 a helical sweep rises from the units wheel. At every warned lever the wheel above advances one digit; if that wheel stood at 9 it warns the next, so one carry can run through a whole row of nines. The givers are restored at the same time.

Turn 3

Even into odd: Δ2 → Δ1, Δ4 → Δ3, Δ6 → Δ5. Column f gives its value a second time, to the printer: it drops into mesh with thirty-one copy sectors and counts down, setting a row of thirty-one type wheels. At the end of the turn the platen strikes the paper onto the type and the anvil lifts the stereotype tray against it.

Turn 4

Carries on Δ1, Δ3 and Δ5. The givers are restored, f climbs back to its digits, the paper is fed one line and the tray advances one line. One cycle, one row of the table.

The setting trick

Because the additions interleave (turn 1 adds Δ1 into f before Δ2 is added into Δ1 in turn 3), each even difference has to run one step behind the odd one above it. The initial registers are therefore not the plain row of differences. For n3 they are f 0, Δ1 1, Δ2 0, Δ3 6, and the page derives them from the forward differences of whatever polynomial you enter.

The carry close-up

The clip is cycle 60 of the logarithm table. Watch the carry poses the figure in cycle 9 of the n7 table, where f = 4,782,969 takes Δ1 = 5,217,031: the units wheel passes 9 → 0 and a single carry runs up through 6 nines to make 10,000,000. On a wide screen with a mouse the stage zooms in on column f and runs that turn at a quarter speed; Escape or a click brings the whole engine back.

Turn 3

The other half add; column f goes to the printer.

Turn 4

Last carries; the paper and the tray advance one line.

Try

Set it to a real table

Tap a table and the engine sets its wheels and runs twenty rows.

Checking copy

nxenginetrue valueerror

More: how the arithmetic stays exact

The registers are eight 31-digit integers, kept as BigInts, never floats. A negative value is a ten's complement, exactly as on the wheels: a register at or above 1031 ⁄ 2 reads as itself minus 1031. Every addition is modulo 1031, so what the wheels show, what the paper prints and what the table says are one set of digits.

The presets are real tables. n7 uses all eight columns, with Δ7 = 7! = 5,040; n3, n2 and x2 + x + 41 are exact polynomials, so the engine's values are exact. Logarithms, sines and compound interest are not polynomials, so they are tabulated the way Babbage's tables were, through a polynomial approximation: a degree-7 least-squares fit over the table's range, with the fit's largest error stated on the card. For log10 x over x = 10,000 … 10,999 it is 4.45 × 10-9; for sin x° over 0 … 90 it is 4.62 × 10-8; for 1.05n over n = 0 … 50 it is 7.92 × 10-6, an exponential showing where a degree-7 fit runs out.

The logarithm table is there because Babbage published his own: Table of Logarithms of the Natural Numbers from 1 to 108,000, London, 1827, and reissued for decades. Errors in printed tables were the reason he wanted an engine at all.

The checking copy runs the model in your browser for 1,000 rows of whatever the engine is set to (or a fitted table's whole range, where that is shorter) and hands you a file: the engine's value, the true value and the difference, row by row. For an exact polynomial the true values are computed exactly too. Nothing leaves your browser.

History

The real engine

Babbage never saw it built. The Science Museum did, 140 years later, and it works.

  1. Designed by Charles Babbage
  2. Calculating section built, Science Museum, London, led by Doron Swade
  3. Printing and stereotyping apparatus added
  4. Second engine, built for Nathan Myhrvold, shown at the Computer History Museum
Close-up of two columns of figure wheels with the carry levers between them, one column standing at a row of nines with the index bar reading each digit, the sweep lit amber part way up.
Carry levers between two columns, a row of nines waiting.
More: the build and the numbers

Charles Babbage designed Difference Engine No. 2 between 1846 and 1849, and it was never built in his lifetime. The drawings waited.

From 1985 to 1991 the Science Museum, London built a working calculating section to those drawings, in a project led by Doron Swade, then its Curator of Computing; the main part was finished in June 1991, for the bicentenary of Babbage's birth, and the printing and stereotyping apparatus was completed and added in 2002. The engine has 8 columns of 31 figure wheels and tabulates polynomials of the 7th order; it has about 8,000 parts, weighs about five tons and measures 11 ft × 7 ft. It is in the museum's collection as object 1992-556.

The printer is the design Babbage also intended for the Analytical Engine. Its first purpose is stereotyping: pressing the result's digits into a tray of soft material (plaster of Paris) to make a flong from which plates for a table book can be cast. Its paper output is an inked checking copy, and it typesets with alterable formatting: line height, number of columns and column margins.

A second engine, completed for Nathan Myhrvold, was on display and demonstrated at the Computer History Museum in Mountain View, California from May 2008 to January 2016.

So the question Babbage could not settle, whether the design works, was settled by the people who built it. This page asks a smaller one: what does the engine look like while it is working, wheel by wheel, carry by carry? Everything you see here moves because the model says it must.

Honesty

Faithful and simplified

The arithmetic and the parts count are Babbage's; some of the movements are this figure's own.

As designed

  • Eight columns, 31 wheels each
  • Four-turn cycle, carries upward
  • Column f to the printer
  • Exact 31-digit registers

This figure's own

  • Columns lift into mesh
  • Rack-driven carry sweeps
  • Six cams on the shaft
  • Type wheels unwind to zero
The full list

As designed

  • Eight columns of thirty-one figure wheels, seven columns of sector gears between them, a carry lever for every wheel; polynomials of the seventh order in 31 digits.
  • One cycle is one turn of the main shaft, four turns of the crank through 4:1 gearing. Turns 1 and 3 interleave the odd and even additions; turns 2 and 4 carry from the units wheel up, so a carry can run through a row of nines; the givers are restored.
  • Column f is taken off in turn 3 by a sector gear to the printing apparatus at the left end, on its own bed, bolted to the engine's bed and driven from the coupling flange on the main shaft.
  • The printer makes an inked checking copy on paper and impresses the digits into a tray of soft material for a stereotype mould, with adjustable line height, columns and margins (here the column-shift lever and the line-height nut on the tray slide).
  • Exact 31-digit registers with ten's complements for negatives; tables of functions that are not polynomials made through polynomial approximation, as Babbage's were.

This figure's own devices

  • The sector lift: the real sector gears slide axially into mesh. Here the columns themselves rise or drop half a pitch into mesh with sectors set above or below the tooth line.
  • The carry sweeps: real ones are helical arms on rotating shafts. Here the helices are turned by rack bars from two carry cams.
  • Six cams on the main shaft: two for the carry racks, four for the printer's platen, anvil, ink roller and paper feed. The figure's arrangement, not a survey of Babbage's.
  • The carry side: the levers and sweeps stand at the front-left of each column, where you can watch them work.
  • The copy linkage: f drops into mesh with thirty-one copy sectors and counts down like any giver; each copy sector turns a copy wheel whose hub pinion moves a rack 1.335 cm per digit; the racks run through the left standard into the printer, turn vertical type spindles, and a face crown at each spindle's foot turns its type wheel 9° per digit. The sources name a sector gear and the printer's features, not the linkage between them.
  • The type wheels unwind to zero after each strike; a real printer would hold the type between strokes. The ten digits are engraved four times round each type rim, so the paper behind and the tray below take the same figure. The paper is fed 5.2 cm a line and the lead screw advances the tray 3.0 cm.
  • 30 crank rpm is the figure's running speed, not a historical one.

Making

How it was built

Nothing here is drawn by hand.

  • 2,221solids
  • 0floating line ends
  • 2,976poses matched
  • 60fps

The figure is an isometric SVG written by a build script with the open-source Anatomy skill for Claude Code: a parts list first, then every part as a small solid, recorded for audit. One model, engine.mjs, drives the SVG, the printer and the 3D view.

The 3D view, close up: figure wheels with forty-tooth rims and engraved digit drums, carry levers and a helical sweep, posed mid-carry with the wheels taking the carry lit amber.
The 3D view, posed by the same model.
Glow mode, close up: the wheels taking a carry glow amber, with soft halos, while the rest of the column stays line-drawn.
Glow mode: the wheels taking a carry are lit.
More: the audit and the checks
  • 2,221 recorded solids
  • 1,375 painter's items
  • 10 resting states audited
  • 106,573 overlaps checked against 11,503 order rules
  • 0 floating line ends
  • 248 figure wheels · 248 carry levers · 31 type wheels

Every part is a small solid with four-tone shading, and the script records what it draws. The audit passes when nothing passes through anything and nothing is painted out of order, and a second check walks every fine texture line and requires both its ends to land on a stroke, a dot or an outline.

The model behind it all, engine.mjs, has no DOM and no geometry: registers, the cycle, the pose at any crank angle. It is unit-tested, and the page, the printer and the 3D view read from it.

The 3D view is three.js, generated from the same layout and the same part builders rather than modelled separately, and then checked against the model: 2,976 figure-wheel poses and 372 type-wheel poses compared at the end of every turn across three presets, worst error 0.000°, zero failures. It draws in 38 calls and holds 60 fps at 1440 × 900, and at 390 px wide with a 4× CPU throttle.

Glow mode, which lights whatever is working, follows April Zhu's iso-glow. With it on, the SVG spends under 7 ms of script per frame.

Credits

Sources and credits

Dates and dimensions from the Science Museum; the method from Wikipedia and the Computer History Museum; the story from Doron Swade.

The five sources
  • Babbage's Difference Engine No 2, 2002, Science Museum Group Collection, object 1992-556: the engine itself, its dates and its dimensions.
  • Difference engine, Wikipedia: the method of differences, the four-step cycle and the sector gear to the printer, the Science Museum build of 1985–1991 and the printer of 2002, the Myhrvold engine, parts and weight.
  • The Babbage Engine, Computer History Museum, in particular The Engines and A Modern Sequel: the printer's stereotyping and formatting, the modern build, and the exhibition of May 2008 to January 2016.
  • Charles Babbage, Table of Logarithms of the Natural Numbers from 1 to 108000 (London, 1827), scanned at the Internet Archive, with the 1831 and 1841 editions.
  • Doron Swade, The Cogwheel Brain (Abacus, 2001), published in the United States as The Difference Engine: Charles Babbage and the Quest to Build the First Computer (Viking, 2001; Penguin paperback 2002, ISBN 978-0-14-200144-8): the story of the build by the curator who led it. See Doron Swade on Wikipedia.

Built by Kevin Owens with Claude Code. Figure with Anatomy by wheresryan22 (MIT); glow mode after iso-glow by April Zhu (MIT); 3D view with three.js (MIT), vendored so the page loads nothing off-site.

Licences: Anatomy · three.js · dark figure · 3D view

If you know the real engine and see something wrong here, tell me. Corrections are credited.

Also: the Enigma and Turing's codebreaking machine · All machines