[proofplan]
We first remove the harmless integer part and sign, so it is enough to discuss numbers in $[0,1)$. A periodic decimal is then written as a finite initial block followed by a repeating block, and its value is computed by summing a geometric [series](/pages/1364). Conversely, a rational number is reduced so that the part of its denominator not divisible by $2$ or $5$ is coprime to $10$; the [Fermat-Euler Theorem](/theorems/732) then produces a repeating block whose length divides $\varphi(q)$.
[/proofplan]
[step:Reduce to fractional parts and fix the decimal notation]
Let $x \in \mathbb{R}$. Write $x = \varepsilon(N + y)$, where $\varepsilon \in \{-1,1\}$, $N \in \mathbb{Z}$, and $y \in [0,1)$. Since $\varepsilon$ and $N$ are rational, $x \in \mathbb{Q}$ if and only if $y \in \mathbb{Q}$. Also, adding an integer part and changing sign do not affect whether the fractional decimal expansion is eventually periodic. Hence it suffices to prove the theorem for $y \in [0,1)$.
For digits, let $d_1,\dots,d_k,a_1,\dots,a_m \in \{0,1,\dots,9\}$ with $m \ge 1$. Define the integers
\begin{align*}
D &= \sum_{i=1}^{k} d_i 10^{k-i}, \\
A &= \sum_{j=1}^{m} a_j 10^{m-j}.
\end{align*}
Thus $D$ is the integer represented by the finite block $d_1\cdots d_k$, and $A$ is the integer represented by the repeating block $a_1\cdots a_m$, allowing leading zeros in either block.
[/step]
[step:Sum the repeating decimal block as a geometric series]
Suppose $y \in [0,1)$ has periodic decimal expansion
\begin{align*}
y = 0.d_1\cdots d_k\overline{a_1\cdots a_m}.
\end{align*}
With $D$ and $A$ as defined above, the decimal expansion gives
\begin{align*}
y
&= \frac{D}{10^k}
+ \frac{A}{10^k}\left(\frac{1}{10^m} + \frac{1}{10^{2m}} + \frac{1}{10^{3m}} + \cdots\right).
\end{align*}
The ratio of the geometric series is $10^{-m}$, and $|10^{-m}| < 1$, so the geometric series formula gives
\begin{align*}
\frac{1}{10^m} + \frac{1}{10^{2m}} + \frac{1}{10^{3m}} + \cdots
&= \frac{10^{-m}}{1 - 10^{-m}} \\
&= \frac{1}{10^m - 1}.
\end{align*}
Therefore
\begin{align*}
y
&= \frac{D}{10^k} + \frac{A}{10^k(10^m - 1)} \\
&= \frac{D(10^m - 1) + A}{10^k(10^m - 1)}.
\end{align*}
The numerator and denominator are integers and the denominator is nonzero, so $y \in \mathbb{Q}$. Hence every [real number](/pages/1303) with a periodic decimal expansion is rational.
[guided]
Assume
\begin{align*}
y = 0.d_1\cdots d_k\overline{a_1\cdots a_m}
\end{align*}
with $y \in [0,1)$, digits $d_i,a_j \in \{0,1,\dots,9\}$, and $m \ge 1$. The finite non-repeating block contributes the integer $D$ shifted $k$ decimal places:
\begin{align*}
\frac{D}{10^k}.
\end{align*}
The repeating block contributes the same integer $A$ shifted first by $k+m$ decimal places, then by $k+2m$ places, and so on. Hence
\begin{align*}
y
&= \frac{D}{10^k}
+ \frac{A}{10^{k+m}}
+ \frac{A}{10^{k+2m}}
+ \frac{A}{10^{k+3m}}
+ \cdots \\
&= \frac{D}{10^k}
+ \frac{A}{10^k}\left(\frac{1}{10^m} + \frac{1}{10^{2m}} + \frac{1}{10^{3m}} + \cdots\right).
\end{align*}
The infinite series in parentheses is geometric with first term $10^{-m}$ and ratio $10^{-m}$. Since $m \ge 1$, we have $|10^{-m}| < 1$, so the geometric series formula applies:
\begin{align*}
\frac{1}{10^m} + \frac{1}{10^{2m}} + \frac{1}{10^{3m}} + \cdots
&= \frac{10^{-m}}{1 - 10^{-m}} \\
&= \frac{1}{10^m - 1}.
\end{align*}
Substituting this value gives
\begin{align*}
y
&= \frac{D}{10^k} + \frac{A}{10^k(10^m - 1)} \\
&= \frac{D(10^m - 1) + A}{10^k(10^m - 1)}.
\end{align*}
This is a quotient of integers. The denominator $10^k(10^m - 1)$ is nonzero because $m \ge 1$, so $y \in \mathbb{Q}$. Since the integer part and sign were removed in the first step without changing rationality, the original real number is rational.
[/guided]
[/step]
[step:Separate the powers of $2$ and $5$ from the rational denominator]
Conversely, suppose $y \in [0,1) \cap \mathbb{Q}$. Choose integers $p$ and $r$ with $r \ge 1$, $\gcd(p,r)=1$, and
\begin{align*}
y = \frac{p}{r}.
\end{align*}
Write
\begin{align*}
r = 2^c 5^d q,
\end{align*}
where $c,d \in \mathbb{N} \cup \{0\}$, $q \in \mathbb{N}$, and $\gcd(q,10)=1$. Let
\begin{align*}
s = \max\{c,d\}.
\end{align*}
Then
\begin{align*}
10^s y
= \frac{10^s p}{2^c5^d q}
= \frac{2^{s-c}5^{s-d}p}{q}.
\end{align*}
Define
\begin{align*}
a = 2^{s-c}5^{s-d}p \in \mathbb{Z}.
\end{align*}
By the [division algorithm](/theorems/725), there exist $n \in \mathbb{Z}$ and $b \in \{0,1,\dots,q-1\}$ such that
\begin{align*}
a = nq + b.
\end{align*}
Hence
\begin{align*}
10^s y = n + \frac{b}{q}.
\end{align*}
It remains to prove that $b/q$ has a periodic decimal expansion; multiplying by $10^{-s}$ only inserts a finite initial decimal block.
[guided]
Let $y \in [0,1)$ be rational. Choose a reduced fraction
\begin{align*}
y = \frac{p}{r},
\end{align*}
where $p,r \in \mathbb{Z}$, $r \ge 1$, and $\gcd(p,r)=1$. Every positive integer denominator can be written by separating its factors of $2$ and $5$:
\begin{align*}
r = 2^c5^d q,
\end{align*}
where $c,d \in \mathbb{N}\cup\{0\}$, $q \in \mathbb{N}$, and $\gcd(q,10)=1$. The factors $2$ and $5$ are exactly the factors already present in powers of $10$, so multiplying by a sufficiently large power of $10$ removes them from the denominator.
Let
\begin{align*}
s = \max\{c,d\}.
\end{align*}
Then $s-c \ge 0$ and $s-d \ge 0$, so
\begin{align*}
10^s y
&= \frac{10^s p}{2^c5^d q} \\
&= \frac{2^s5^s p}{2^c5^d q} \\
&= \frac{2^{s-c}5^{s-d}p}{q}.
\end{align*}
Define the integer
\begin{align*}
a = 2^{s-c}5^{s-d}p.
\end{align*}
We now isolate the integer part of $a/q$. By the division algorithm applied to the integer $a$ and the positive integer $q$, there exist $n \in \mathbb{Z}$ and $b \in \{0,1,\dots,q-1\}$ such that
\begin{align*}
a = nq + b.
\end{align*}
Dividing by $q$ gives
\begin{align*}
10^s y = \frac{a}{q} = n + \frac{b}{q}.
\end{align*}
Thus the only remaining issue is the fractional term $b/q$, whose denominator is coprime to $10$. Once $b/q$ is shown to have a periodic decimal expansion, multiplying by $10^{-s}$ shifts the decimal point $s$ places to the left, adding only a finite initial block.
[/guided]
[/step]
[step:Use the Fermat-Euler theorem to produce a repeating denominator]
If $q=1$, then $b=0$, so $b/q=0$ has the periodic decimal expansion $0.\overline{0}$. Assume now that $q \ge 2$. Since $\gcd(q,10)=1$, the [Fermat-Euler Theorem](/theorems/785) applies and gives
\begin{align*}
10^{\varphi(q)} \equiv 1 \pmod q,
\end{align*}
where $\varphi(q)$ denotes Euler's totient function. Therefore there exists an integer $K \in \mathbb{Z}$ such that
\begin{align*}
10^{\varphi(q)} - 1 = Kq.
\end{align*}
Since $10^{\varphi(q)} - 1 > 0$ and $q>0$, this integer satisfies $K>0$.
[guided]
If $q=1$, then the division-algorithm remainder satisfies $b \in \{0\}$, so $b/q=0$. The decimal expansion $0.\overline{0}$ is periodic, and there is nothing more to prove in this case.
Now assume $q \ge 2$. The denominator $q$ was constructed by removing all factors of $2$ and $5$ from the original denominator, so $\gcd(q,10)=1$. This is exactly the hypothesis needed to apply the Fermat-Euler Theorem, which states that when an integer is coprime to $q$, its $\varphi(q)$-th power is congruent to $1$ modulo $q$. Applying it to the integer $10$ gives
\begin{align*}
10^{\varphi(q)} \equiv 1 \pmod q.
\end{align*}
By the definition of congruence modulo $q$, this means that $q$ divides $10^{\varphi(q)} - 1$. Hence there exists $K \in \mathbb{Z}$ such that
\begin{align*}
10^{\varphi(q)} - 1 = Kq.
\end{align*}
The left-hand side is positive because $\varphi(q) \ge 1$ and $q \ge 2$, while $q$ is positive. Therefore $K>0$. This integer $K$ is the bridge between the denominator $q$ and a denominator of the form $10^m-1$, which is precisely the denominator of a repeating decimal block.
[/guided]
[/step]
[step:Construct the periodic block from the congruence]
Let
\begin{align*}
m = \varphi(q).
\end{align*}
Using $10^m - 1 = Kq$, we obtain
\begin{align*}
\frac{b}{q}
&= \frac{Kb}{Kq} \\
&= \frac{Kb}{10^m - 1}.
\end{align*}
Since $0 \le b < q$ and $K>0$,
\begin{align*}
0 \le Kb < Kq = 10^m - 1 < 10^m.
\end{align*}
Therefore $Kb$ can be written as an $m$-digit decimal block, allowing leading zeros. That is, there exist digits $e_1,\dots,e_m \in \{0,1,\dots,9\}$ such that
\begin{align*}
Kb = \sum_{j=1}^{m} e_j 10^{m-j}.
\end{align*}
The geometric series formula gives
\begin{align*}
0.\overline{e_1\cdots e_m}
&= Kb\left(\frac{1}{10^m} + \frac{1}{10^{2m}} + \frac{1}{10^{3m}} + \cdots\right) \\
&= Kb \cdot \frac{1}{10^m - 1} \\
&= \frac{b}{q}.
\end{align*}
Thus $b/q$ has a periodic decimal expansion with repeating block $e_1\cdots e_m$.
[guided]
Set
\begin{align*}
m = \varphi(q).
\end{align*}
From the previous step we have
\begin{align*}
10^m - 1 = Kq
\end{align*}
for some positive integer $K$. This allows us to rewrite the denominator of $b/q$ in the standard form associated with a repeating decimal:
\begin{align*}
\frac{b}{q}
&= \frac{Kb}{Kq} \\
&= \frac{Kb}{10^m - 1}.
\end{align*}
We need the numerator $Kb$ to fit into a block of exactly $m$ decimal digits. Since $b$ is the remainder from division by $q$, we have $0 \le b < q$. Multiplying by the positive integer $K$ gives
\begin{align*}
0 \le Kb < Kq.
\end{align*}
Using $Kq = 10^m - 1$, this becomes
\begin{align*}
0 \le Kb < 10^m - 1 < 10^m.
\end{align*}
Therefore $Kb$ is an integer between $0$ and $10^m-1$, so it has an $m$-digit decimal representation after padding with leading zeros if necessary. Thus there exist digits $e_1,\dots,e_m \in \{0,1,\dots,9\}$ such that
\begin{align*}
Kb = \sum_{j=1}^{m} e_j10^{m-j}.
\end{align*}
Now compute the value of the repeating decimal with block $e_1\cdots e_m$. The first occurrence of the block contributes $Kb/10^m$, the second contributes $Kb/10^{2m}$, and so on:
\begin{align*}
0.\overline{e_1\cdots e_m}
&= Kb\left(\frac{1}{10^m} + \frac{1}{10^{2m}} + \frac{1}{10^{3m}} + \cdots\right).
\end{align*}
The series is geometric with ratio $10^{-m}$, whose absolute value is less than $1$, so
\begin{align*}
\frac{1}{10^m} + \frac{1}{10^{2m}} + \frac{1}{10^{3m}} + \cdots
= \frac{1}{10^m - 1}.
\end{align*}
Substituting this value gives
\begin{align*}
0.\overline{e_1\cdots e_m}
&= \frac{Kb}{10^m - 1} \\
&= \frac{b}{q}.
\end{align*}
Thus $b/q$ has a periodic decimal expansion.
[/guided]
[/step]
[step:Transfer periodicity back to the original rational number]
From the previous steps,
\begin{align*}
10^s y = n + \frac{b}{q},
\end{align*}
and $b/q$ has a periodic decimal expansion. Hence $10^s y$ has a periodic decimal expansion, and multiplying by $10^{-s}$ shifts the decimal point $s$ places to the left, producing at most $s$ additional non-repeating digits. Therefore $y$ has a periodic decimal expansion. Restoring the integer part and sign from the first step shows that every rational real number has a periodic decimal expansion.
Combining this with the forward implication proves that a real number has a periodic decimal expansion if and only if it is rational.
[/step]