Stern–Brocot Tree Explorer

Find any fraction in the Stern–Brocot tree, which contains every positive fraction exactly once, as a path of left and right moves from 1/1, or turn a path back into its fraction, with each mediant shown.

Explorer Number Systems Updated Oct 3, 2026
How to Use
  1. Choose fraction to path or path to fraction.
  2. Type a positive fraction such as 3/7 (or a decimal), or a path of Ls and Rs such as LLRR.
  3. Read the path, the fraction, the depth and the run-lengths of the path.
  4. The drawing follows the path down the tree; Show Work lists each mediant.
  5. For decimals, set how deep to search; the deepest node reached is the closest simple fraction on the way.
Input
3/7 or 0.618L and R
Presets
Down the tree
Path from 1/1
—
Fraction
—
Depth
—
Run-lengths
—

Worked Example

Finding 3/7. Start at 1/1, between 0/1 and 1/0. 3/7 is smaller, so go L: the new bounds are 0/1 and 1/1, and the mediant is 1/2. Still smaller: L, bounds 0/1 and 1/2, mediant 1/3. Now 3/7 is larger: R, bounds 1/3 and 1/2, mediant 2/5. Larger again: R, bounds 2/5 and 1/2, mediant (2 + 1)/(5 + 2) = 3/7. The path is LLRR.

Following RRLRL. R: 2/1. R: 3/1. L: mediant of 2/1 and 3/1, 5/2. R: mediant of 5/2 and 3/1, 8/3. L: mediant of 5/2 and 8/3, 13/5.

The common mistake: adding fractions the wrong way. The mediant (a + c)/(b + d) is not the sum or the average: the mediant of 1/2 and 1/3 is 2/5 = 0.4, while their average is 5/12 ≈ 0.417. Using the average instead breaks the tree, which only works because mediants are always in lowest terms here.

Show Work

Enter a fraction to see the step-by-step working.

Formulas

Mediant
a/b ⊕ c/d = (a + c)/(b + d)
Start
0/1 < 1/1 < 1/0
Step
smaller → L (new upper bound) · larger → R
Neighbours
bc − ad = 1
for the bounds a/b < c/d of any node
Continued fraction
[a₀; a₁, …, aₙ] → Ra₀La₁…aₙ−1

A Clockmaker’s Tree

Achille Brocot was a Paris clockmaker who needed gear ratios close to awkward astronomical values, using gears with a reasonable number of teeth. In 1861 he published a method that, step by step, narrows the gap between two fractions using mediants: the tree that now bears his name. Moritz Stern had described the same structure three years earlier, studying a sequence now called Stern’s diatomic sequence.

The tree shows that the rational numbers can be listed one by one with no repeats, and it is closely related to Farey sequences, Ford circles and the Calkin–Wilf tree. Because each node is the simplest fraction in its interval, descending the tree is a way to find best rational approximations, the same results that continued fractions give.

About This Calculator

This explorer finds the path of left and right moves from 1/1 to any positive fraction in the Stern–Brocot tree, or the fraction at the end of a path, listing each mediant and the bounds around it. It also gives the run-lengths of the path, the continued fraction in disguise, and the node’s two children. Decimals are followed down to the depth you choose.

Everything runs in your browser; nothing is sent anywhere.

Related calculators: Continued Fraction Converter, Decimal to Fraction Converter, and Egyptian Fractions.

Frequently Asked Questions

What is the Stern–Brocot tree?

An infinite binary tree that contains every positive fraction exactly once, in lowest terms. It starts at 1/1, between the bounds 0/1 and 1/0. Each node is the mediant of its two bounds, (a + c)/(b + d), and the tree is ordered: everything to the left of a node is smaller, everything to the right larger.

How do I find the path to a fraction?

Start at 1/1. If your fraction is smaller, go left (L) and make the current node the new upper bound; if larger, go right (R) and make it the lower bound. The next node is the mediant of the bounds. For 3/7: 1/1 → L → 1/2 → L → 1/3 → R → 2/5 → R → 3/7, so the path is LLRR.

What does the path have to do with continued fractions?

The lengths of the runs of equal letters are the continued fraction, with the last term reduced by one. 3/7 = [0; 2, 3] gives R⁰L²R², which is LLRR. 355/113 = [3; 7, 16] gives R³L⁷R¹⁵.

What is a mediant?

The fraction made by adding numerators and adding denominators: the mediant of 1/3 and 1/2 is 2/5. It always lies strictly between the two fractions, and in the Stern–Brocot tree it is the simplest fraction between its bounds, which is why the tree finds best approximations.

Who discovered it?

The German mathematician Moritz Stern described it in 1858, and the French clockmaker Achille Brocot independently in 1861, using it to design gear trains: to approximate a ratio with gears of manageable size, he walked down this tree.

How do I use the Stern–Brocot Tree Explorer?

Just type your numbers. The answer shows up right away — there is no button to press. Change anything and it updates by itself.

Is it free? Does it work without internet?

Yes to both. It is free with no sign-up, and once the page has loaded it keeps working even with no internet.

Where does my data go?

Nowhere — every calculation runs on your own device. Nothing you enter is uploaded, logged, or stored.

Common Use Cases

Coursework

3/7 is at LLRR: 1/1, 1/2, 1/3, 2/5, 3/7.

Approximations

355/113 is at R³L⁷R¹⁵, 25 steps down.

Paths to fractions

RRLRL leads to 13/5.

Gear trains

Walk towards a decimal ratio and stop at a fraction with small numbers, as Brocot did.

Last updated: