If you divide 1 by 3 the long way, the digits of the answer are 0.333333\ldots forever. If you divide 1 by 7, they are 0.142857142857\ldots forever. Every fraction of two whole numbers becomes either a terminating decimal or a repeating decimal — no other outcome is possible. The reason is not magic. It is sitting right there in the long division algorithm, in the column of remainders that you write down as you work.

Long division, one step at a time

Take \tfrac{1}{7}. The number you're dividing (1) is smaller than the divisor (7), so you put a "0." in the quotient and start lifting in zeros.

At this point, the remainder is 1 — the same remainder you started with. The next step will be "divide 10 by 7," the same step as the first one. From here, everything repeats. The digits 1, 4, 2, 8, 5, 7 will come out again, in the same order, forever.

\frac{1}{7} = 0.\overline{142857}.

The bar over 142857 says this block repeats. And the reason it repeats is that the remainder came back to a value we'd already seen.

Long division of one by seven showing the repeating remainderA vertical table tracking six steps of long division dividing one by seven. Each row shows the current dividend chunk, how many times seven fits in, and the remainder carried to the next row. The sequence of remainders goes one, three, two, six, four, five, one. The final one matches the starting one, and an arrow labelled "loop returns here" highlights the repetition. step dividend digit written remainder 11013 23042 32026 46084 54055 65071 step 7 10 1 (again) 3 (again) remainder loops back 1/7 = 0.142857142857… the six-digit block repeats forever because the remainder 1 has returned
The six steps of long division for $1 \div 7$. Each row records the remainder in the accent colour. The remainders march $1, 3, 2, 6, 4, 5$, then back to $1$. The moment the remainder repeats an earlier value, the algorithm is forced to reproduce the same digits in the quotient from that point on. The whole repeating block $142857$ is exactly six digits because it took six steps for a remainder to recur.

Why a repeat is guaranteed

This is the pigeonhole punchline. When you divide by 7, the remainder at each step is one of \{0, 1, 2, 3, 4, 5, 6\} — exactly seven possibilities. If the remainder ever hits 0, the division terminates: no more digits. If it never hits 0, then the remainders must keep cycling through the six nonzero values \{1, 2, 3, 4, 5, 6\}. After at most six steps, one of those remainders has to reappear — there is nowhere else for it to go. And once a remainder reappears, the algorithm reproduces the same digits, in the same order, starting from that point.

So for any divisor q:

No third option is possible. This is why every rational number — every fraction of whole numbers — has a decimal expansion that either terminates or repeats. Nothing else can happen, purely because there are only finitely many possible remainders.

The bound on the repeat length

The length of the repeating block is called the period of the decimal. The pigeonhole argument tells you the period is at most q - 1, where q is the (reduced) denominator. For \tfrac{1}{7}, the period is exactly 6 = 7 - 1 — it achieves the maximum. That's why 1/7 cycles through all six nonzero remainders before repeating.

For other denominators, the period might be shorter. \tfrac{1}{3} = 0.\overline{3} has period 1. \tfrac{1}{11} = 0.\overline{09} has period 2. \tfrac{1}{13} = 0.\overline{076923} has period 6. The period depends on a subtle fact about 10 modulo q — specifically, it is the smallest positive integer k such that 10^k \equiv 1 \pmod{q}. You don't need that machinery yet, but the idea is: the period is at most q - 1, and equals q - 1 exactly when 10 is a primitive root modulo q.

Try it live — drag the denominator and watch the block emerge

Interactive long division readout for one over qA horizontal slider controlling q from two to twenty. Readouts above display the current value of q, the decimal expansion of one over q to several digits, and the length of the repeating block if it exists. As the reader drags q, the decimal expansion updates: at q equals two, the readout shows zero point five (terminates); at q equals three, it shows zero point three repeating; at q equals seven, the six-digit repeating block appears. (showing up to 12 decimal digits) try q = 2, 3, 4, 5, 7, 8, 11 — watch which terminate and which repeat 2 11 20 ↔ drag to choose q
Drag the slider. At $q = 2$ you get $0.5$ — terminates. At $q = 3$ you get $0.333\ldots$ — period one. At $q = 7$ you get a long block of decimals with the $142857$ loop hiding inside. At $q = 8$ you get $0.125$ — terminates again. The pattern of which denominators give terminating versus repeating decimals is the starting point for the next section.

Which denominators terminate?

A fraction \tfrac{p}{q} in lowest terms terminates as a decimal if and only if the denominator q has no prime factors other than 2 and 5. In other words, q must be of the form 2^a \times 5^b for some non-negative integers a, b.

This is because 10 = 2 \times 5, and terminating decimals are just fractions with a denominator that is a power of 10. Any denominator built only from 2s and 5s can be scaled up to a power of 10 by multiplying top and bottom by whatever is missing. Any other prime factor — 3, 7, 11, 13, \ldots — will not divide 10^n for any n, so the decimal cannot terminate and must repeat.

Everything else repeats. For the longer discussion, see Fractions and Decimals.

Going the other way — from repeating decimal back to fraction

Once you know a decimal repeats, you can run the algorithm in reverse to recover the fraction. This is the algebraic trick:

The trick recovers the fraction exactly. See Convert a Repeating Decimal to a Fraction for the full recipe and a second worked example.

The takeaway

Every rational fraction is one of these two shapes. Recognising which, and finding the period, is a skill that shows up in every base-representation problem in higher mathematics — from clock arithmetic to cryptography to music theory.

Related: Fractions and Decimals · Convert a Repeating Decimal to a Fraction — the Multiply-and-Subtract Trick · Test If a Number Is Rational by Looking for Its Repeating Block · Non-Terminating vs Non-Repeating — Same Thing or Different?