Proof. We proceed in two steps: first show f is bounded above on [a,b], then show the supremum is attained.
Step 1: f is bounded above
Suppose, for contradiction, that f is not bounded above on [a,b]. Then there exists a sequence {xn}⊂[a,b] such that f(xn)>n for each n∈N.
Since {xn}⊂[a,b] and [a,b] is closed and bounded, the Bolzano--Weierstrass theorem guarantees a convergent subsequence {xnk} with limit c∈[a,b]. That is, xnk→c as k→∞.
By continuity of f at c,
[
f(x_{n_k}) \to f(c).
]
But f(xnk)>nk→+∞ as k→∞, so f(c)=+∞, which is impossible since f(c)∈R. This contradiction implies f is bounded above on [a,b].
Let
[
M = \sup { f(x) : x \in [a,b] } < +\infty.
]
Step 2: M is attained
By definition of the supremum, for each n∈N there exists yn∈[a,b] such that
[
f(y_n) > M - \frac{1}{n}.
]
Again, {yn}⊂[a,b] has a convergent subsequence {ynk} with limit d∈[a,b], i.e., ynk→d as k→∞.
By continuity,
[
f(y_{n_k}) \to f(d).
]
Taking the limit in the inequality above (along the subsequence),
[
f(d) = \lim_{k \to \infty} f(y_{n_k}) \geq \lim_{k \to \infty} \left( M - \frac{1}{n_k} \right) = M.
]
But M is an upper bound, so f(d)≤M. Thus f(d)=M, as required.