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.
- Bring down a 0: now you're dividing 10 by 7. It goes in once, remainder 3. Write 1 in the quotient.
- Bring down another 0: divide 30 by 7. It goes in four times, 4 \times 7 = 28, remainder 2. Write 4.
- Divide 20 by 7. Twice, 2 \times 7 = 14, remainder 6. Write 2.
- Divide 60 by 7. Eight times, 8 \times 7 = 56, remainder 4. Write 8.
- Divide 40 by 7. Five times, 5 \times 7 = 35, remainder 5. Write 5.
- Divide 50 by 7. Seven times, 7 \times 7 = 49, remainder 1. Write 7.
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.
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.
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:
- Either the remainder becomes 0 and the decimal terminates, or
- Some remainder between 1 and q-1 reappears within q-1 steps, and the decimal repeats.
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
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.
- \tfrac{1}{2} = 0.5 — terminates (q = 2).
- \tfrac{1}{4} = 0.25 — terminates (q = 2^2).
- \tfrac{1}{5} = 0.2 — terminates (q = 5).
- \tfrac{1}{8} = 0.125 — terminates (q = 2^3).
- \tfrac{1}{20} = 0.05 — terminates (q = 2^2 \times 5).
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:
- Let x = 0.\overline{142857}.
- Multiply by 10^6 (because the repeat block is 6 digits long). Then 10^6 x = 142857.\overline{142857}.
- Subtract: 10^6 x - x = 142857.\overline{142857} - 0.\overline{142857} = 142857.
- So (10^6 - 1) x = 142857, meaning x = \tfrac{142857}{999999}.
- Simplify: \tfrac{142857}{999999} = \tfrac{1}{7}.
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
- A rational number's decimal expansion either terminates or repeats. No third option.
- The repetition is forced by the pigeonhole principle on the remainder column of long division.
- The period (length of the repeat block) is at most q - 1, where q is the reduced denominator.
- The decimal terminates exactly when q has no prime factors other than 2 or 5.
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?