Let $ (X, d) $ be a metric space, and say $ f : X \longrightarrow \mathbb{R} $ is a continuous function. Can we impose an interesting condition on $ X $ (and $ X $ alone) to ensure that $ f $ is bounded ?
Continuity makes $ f $ "locally bounded", i.e. for every $ x \in X $ there is a $ \delta_x > 0 $ such that $ f $ is bounded on $ B(x, \delta_x) $. Also $ X $ is covered by these $ \{ B(x, \delta_x) : x \in X \} $.
Had we had the provision to pick finitely many points $ x_1, \ldots, x_n \in X $ such that $ X $ is covered by $ \{ B(x_1, \delta_{x_1}), \ldots, B(x_n, \delta_{x_1}) \} $$ \{ B(x_1, \delta_{x_1}), \ldots, B(x_n, \delta_{x_n}) \} $ itself, $ f $ would've been bounded. So if we impose that every cover of $ X $ by open balls has a finite subcover, that will do. This condition is precisely compactness of $ X $.
[This is just one way to motivate compactness. Compactness of a metric space has lot many consequences, especially on how continuous functions behave on that space.]