Download and extract the reader ZIP archive (a compressed collection of files). Links labelled “reader ZIP; extract …” download this archive; after extraction, open the named file. It includes the offline article, full-size PNG images, editable SVG diagrams, complete source code, tests and worksheets.
An extra gear can move the output shaft and reverse its direction without changing the size of the overall speed ratio. The important question is whether the middle part is one idler or two different gears fixed to the same shaft.
This is a paper-and-code experiment in ideal gear geometry. An idler gear sits between the driving and driven gears. A shaft is the rotating support shared by parts that turn together. We will predict angles, deliberately make a direction error, and restore the original arrangement. All supplied records are constructed calculations. No gears were manufactured, powered or measured for this article.
Prepare the drawing and files
You need a computer with CPython, the reference implementation of the Python language, version 3.9 or later; the delivered code uses only its standard library. Author checks used CPython 3.9.6. For the paper experiment use plain paper, a ruler, a protractor and a pencil. A protractor is the semicircular scale used to mark angles. You do not need a motor or a gear kit.
For the offline reader, extract the ZIP archive first, and open reader.html — reader ZIP; extract reader.html or README.txt — reader ZIP; extract README.txt inside the extracted folder. Keep the assets and data folders beside the program. Scalable Vector Graphics (SVG) files are the editable drawings; Portable Network Graphics (PNG) files are their ready-to-view images. Comma-separated values (CSV) files are plain-text tables. Do not run the program from a compressed-folder preview.
One mesh reverses the sign
A pitch circle is the ideal rolling circle used to describe a gear’s motion. It is not the outside tooth outline. For matching gears, the module is pitch diameter divided by tooth count, expressed here in millimetres per tooth. We use standard, unshifted spur-gear pitch circles and module 2 millimetres (mm). A spur gear has teeth parallel to its shaft; unshifted specifies the reference geometry used here. A 20-tooth gear therefore has a 40 mm pitch diameter and 20 mm pitch radius. Smooth paper circles cannot reproduce real tooth engagement; our circles are a drawing model.
View every shaft from the same side. Count counterclockwise turns as positive and clockwise turns as negative. At an ideal external mesh, where two gears touch on their outsides, their pitch-circle surface motions match while the rotations oppose. If z means tooth count, the output/input turn ratio for one mesh is −z_driver / z_driven. We report output turns divided by input turns throughout; some references call its reciprocal the gear ratio.

assets/idler-pitch-geometry.svg for the labels. These are ideal geometric circles, not machinable tooth profiles.For the 20 → 30 → 40 chain, multiply the two signed mesh ratios:
(−20/30) × (−30/40) = +20/40 = +1/2.
The 30 cancels because the same middle gear participates in both meshes. A 50-tooth idler cancels in exactly the same way. One positive input turn produces half a positive output turn in either chain. Removing the idler leaves one external mesh, so the magnitude stays one half but the sign becomes negative.
Size still matters geometrically. Two external pitch circles have center distance m(z₁ + z₂)/2, where m is their common module. With a 30-tooth idler the distances are 50 mm and 70 mm, totaling 120 mm along the straight line of centers. With a 50-tooth idler they are 70 mm and 90 mm, totaling 160 mm. A different tooth count can therefore bridge a different spacing without changing the end ratio. These spans assume collinear centers; a bent train has a different end-to-end distance.
Run the paper prediction experiment
- Draw and label the 20, 30 and 40-tooth pitch circles at their calculated tangent positions. Mark an input reference ray at zero turns. Use the same viewing side for all three shafts.
- On a separate angle sketch, set the input to one quarter turn. Work through each mesh: the idler turns −1/6 turn and the output +1/8 turn. Mark those angles with the protractor. This is a manual prediction, not a motion measurement from smooth circles.
- Repeat for one full input turn. Record the expected output +1/2 turn. Replace only the idler with 50 teeth and redraw the required center positions. Predict +1/2 again.
- Remove the idler as a control. Move the output center to the direct-mesh spacing of 60 mm; do not leave the former spacing and pretend that the gears still touch. Predict −1/2 output turn.
- Restore the 20 → 30 → 40 drawing. Check that the original sign, magnitude and 120 mm span return. If your result differs, inspect the viewing side, number of external meshes and recorded tooth counts.
Use blank-records.csv — reader ZIP; extract data/blank-records.csv as an unfilled worksheet. Its observation cells are intentionally empty and the analyzer leaves them unknown. For your own completed predictions, copy the file, enter the signed output turns and change the row’s provenance to reader_observation. That label identifies your entry; it does not make a paper prediction a physical measurement. Keep a note stating how each value was obtained.
A compound shaft changes the cancellation
A compound gear train uses two different gears rigidly connected to one intermediate shaft. The first driven gear and the next driving gear have equal angular displacement, but their tooth counts need not be equal. Our control has a 20-tooth input driving a 40-tooth gear; a 10-tooth gear on that same middle shaft then drives another 40-tooth output. The two mesh pairs are in different axial planes, meaning separate positions along the shaft.
(−20/40) × (−10/40) = +1/8.
The first 40 and the 10 belong to different gears. They do not cancel merely because they share a shaft. Two input turns now give a quarter output turn. Compare this with two input turns giving one output turn for the simple idler chain.

assets/compound-and-turns.svg.Run the complete model
The program retains tooth ratios as exact rational numbers using Python’s Fraction. The following is the entire model and worksheet analyzer. The package also contains its complete tests and the separate figure-generation source. No external Python package is needed to run the model.
"""Ideal external-gear trains. Python 3.9+, standard library only.
Positive turns mean counterclockwise, viewed from one fixed side.
Pitch circles are geometry, not a manufacturable tooth profile.
"""
import argparse
import csv
import io
import json
import math
from fractions import Fraction
from pathlib import Path
def teeth(value):
if isinstance(value, bool) or not isinstance(value, int) or value < 1:
raise ValueError("tooth counts must be positive integers")
return value
def finite(value, name):
if isinstance(value, bool):
raise ValueError(name + " must be a finite number")
number = float(value)
if not math.isfinite(number):
raise ValueError(name + " must be a finite number")
return number
def simple_ratio(counts):
"""External meshes in a single chain: output turns / input turns."""
if len(counts) < 2:
raise ValueError("a chain needs at least two gears")
checked = [teeth(n) for n in counts]
ratio = Fraction(1)
for first, second in zip(checked, checked[1:]):
ratio *= Fraction(-first, second)
return ratio
def compound_ratio(stages):
"""Pairs (driver, driven); successive pairs share a rigid shaft.
Tooth counts in one pair belong to different meshing gears. The
driven gear of one stage and driver of the next share angular motion.
"""
if not stages:
raise ValueError("at least one mesh stage is required")
ratio = Fraction(1)
for stage in stages:
if len(stage) != 2:
raise ValueError("each stage needs driver and driven counts")
first, second = [teeth(n) for n in stage]
ratio *= Fraction(-first, second)
return ratio
def centers(counts, module_mm):
"""Collinear pitch-circle centers; first center x=0, all y=0."""
module_mm = finite(module_mm, "module_mm")
if module_mm <= 0:
raise ValueError("module_mm must be positive")
checked = [teeth(n) for n in counts]
if len(checked) < 2:
raise ValueError("a chain needs at least two gears")
result = [0.0]
for first, second in zip(checked, checked[1:]):
result.append(result[-1] + module_mm * (first + second) / 2)
return result
CASES = {
"direct": simple_ratio([20, 40]),
"idler30": simple_ratio([20, 30, 40]),
"idler50": simple_ratio([20, 50, 40]),
"two_idlers": simple_ratio([20, 30, 25, 40]),
"compound": compound_ratio([(20, 40), (10, 40)]),
}
def parse_records(text):
"""Blank observations stay blank; malformed or duplicate rows fail."""
reader = csv.DictReader(io.StringIO(text))
required = ["record_id", "case", "input_turns", "observed_output_turns", "provenance"]
if reader.fieldnames != required:
raise ValueError("unexpected CSV columns")
seen, output = set(), []
for row in reader:
if None in row or any(value is None for value in row.values()):
raise ValueError("malformed CSV row")
if not row["record_id"] or row["record_id"] in seen:
raise ValueError("missing or duplicate record_id")
seen.add(row["record_id"])
if row["case"] not in CASES:
raise ValueError("unknown case")
if row["provenance"] not in ("blank", "constructed", "reader_observation"):
raise ValueError("unknown provenance")
input_turns = finite(row["input_turns"], "input_turns")
expected = input_turns * float(CASES[row["case"]])
raw = row["observed_output_turns"].strip()
observed = None if raw == "" else finite(raw, "observed_output_turns")
if row["provenance"] == "blank" and observed is not None:
raise ValueError("blank template must not contain an observation")
if row["provenance"] != "blank" and observed is None:
raise ValueError("nonblank record needs an observation")
output.append(dict(record_id=row["record_id"], case=row["case"],
input_turns=input_turns, expected_output_turns=expected,
observed_output_turns=observed,
residual_turns=None if observed is None else observed - expected,
provenance=row["provenance"]))
return output
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--records", type=Path)
args = parser.parse_args()
if args.records:
result = parse_records(args.records.read_text(encoding="utf-8"))
else:
result = {name: {"ratio": str(ratio), "output_turns_for_one_input": float(ratio)}
for name, ratio in CASES.items()}
print(json.dumps(result, indent=2, allow_nan=False))
if __name__ == "__main__":
main()
From the extracted folder run:
python3 -m unittest discover -v
python3 gear_train.py
python3 gear_train.py --records data/constructed-records.csv
python3 gear_train.py --records data/blank-records.csv
The ordinary run reports −1/2 for direct, 1/2 for both one-idler cases, −1/2 for two_idlers and 1/8 for compound. The constructed table includes a row named FAULT_wrong_direction. It deliberately enters −0.5 for the one-idler output; the residual, entered minus expected, is −1 turn. This is a bookkeeping fault injection, not evidence of a slipping real gear.
Restore that constructed value to +0.5 in a copy and rerun: its residual becomes zero. The original fault file stays preserved. A zero residual only means agreement with the ideal turn relation. It does not certify tooth contact, strength or a real mechanism. The analyzer refuses unknown cases, nonfinite numbers, duplicate record identifiers and malformed columns rather than replacing errors with zero.
What the ideal model leaves out
Backlash is the small free motion between tooth flanks when direction reverses. Elastic deflection, tooth shape, shaft misalignment, bearing friction and power loss can also change an actual mechanism’s response. An extra idler creates another mesh and can add loss even while its tooth count cancels from the ideal speed ratio. Our code does not predict torque capacity, efficiency, printable clearances or safe operating speed.
The author ran 16 host behavior tests, including different idler counts, compound stages, reversed chains, spacing, invalid inputs and CSV faults. No target firmware, manufactured part or physical measurement is claimed. Any real build needs a separately specified compatible gear set, support geometry and its own mechanical qualification.
Challenge: add a second idler
What happens to output direction and magnitude for 20 → 30 → 25 → 40? Predict before running the model.
Worked answer
There are three external meshes, so the sign is negative. Both intermediate tooth counts cancel: (−20/30)(−30/25)(−25/40) = −1/2. One positive input turn gives −1/2 output turn. Adding an idler toggles direction; it does not turn this single chain into a compound reduction.
Sources and related experiments
KHK Gears’ idler-gear explanation supports the simple-train cancellation and positioning role. Its standard spur-gear calculation table supplies the declared unshifted diameter and center-distance relations. Profile-shifted or helical gears need their own geometry. The signed worked cases, paper procedure, code, records and drawings here are original. The source was checked November 30, 2026; no manufacturer’s illustration or downloadable manual is included in the reader archive.
For a different use of geometric spacing, see Connector Pitch: Measure Eleven Gaps Before Choosing a Footprint. For the distinction between a command and actual mechanism behavior, see the servo jitter and power-path experiment. Their public canonical links were checked separately; neither supplies a gear rating.