IDEA: We want to attach two points to the real line and call them $\infty$ and $-\infty$, and we want them to behave as we expect from something we would call $\infty$ and $-\infty$. For that, if we want to talk about the topology of this resulting space, we essentially have to say what are the neighbourhoods of this topology. We still want $(a-\delta,a+\delta)$ to be a neighbourhood of a real number $a$, for example. But we also want neighbourhoods of $\infty$ now. It seems a reasonable attempt to define a neighbourhood of $\infty$ as $(M,\infty]$ for example (note the closed bracket, indicating that $\infty$ is in the set).
Before proceding, I introduce the concept of a basis of a topology. Essentially, the basis of a topology is a smaller, "controlled" set that generates the topology - it says who the open sets are.
Definition: If $X$ is a set, a basis of a topology in $X$ is a collection $\mathcal{B}$ of sets that satisfy the following properties:
(i) For all $x \in X$ there is a set $B$ in $\mathcal{B}$ that contains $x$
(ii) If $x$ is in the intersection of two basis elements $B_1$ and $B_2$, then there is a basis element $B_3$ that contains $x$ and that is contained in the intersection of $B_1$ and $B_2$.
We define the topology $\tau$ generated by $\mathcal{B}$ to be the collection of sets $A$ that satisfy the property that for all $x \in A$, there is a basis element $B$ containing $x$ and contained in $A$.
For example, the balls of a metric space are a basis for its topology (draw it in order to understand!)
Another example of a basis (which is, in fact, a corollary of the balls of metric spaces) are the open intervals in the real line.
Of course, there are technical issues (minor ones, easily solved) that I'll overpass. We have to prove that the topology generated by $\mathcal{B}$ is in fact a topology, as defined in a previous post. If you are interested, you can do it as an exercise.
Now, let's jump into what we wanted!
Definition: Take two points that are not in $\mathbb{R}$ and call them $\infty$ and $-\infty$. Now, define
$$\displaystyle \overline{\mathbb{R}}:=\mathbb{R} \cup \{\infty,-\infty\}$$
Furthermore, define the following basis on $\displaystyle \overline{\mathbb{R}}$:
The basis $\mathcal{B}$ will consist of the open intervals and of the sets $(b, \infty]$ and $[-\infty, a)$ for all $b$ and $a$ real numbers.
That this is in fact a basis (which means that this satisfies the properties listed before) is easy to verify.
Now, in order not to introduce a lot of notations and definitions, I'll not define the subspace topology. It is not a difficult definition, but may be abstract and not enlightening at first. Hence, I'll just assume an intuition in it, in order to justify the following: it seems clear that, if you have
$\displaystyle \overline{\mathbb{R}}$ and pass from it to $\mathbb{R}$, the topology you inherit is exactly the standard topology of $\mathbb{R}$. We will use this fact.
We arrive now at a change of point of view:
In analysis, one often learns the following definition:
We say a sequence $x_n$ converges if there is a real number $L$ such that $\forall \epsilon >0$ there exists a $N \in \mathbb{N}$ such that $n > N \implies |x_n - L| < \epsilon$. In this case, we call $L= \lim x_n$. Otherwise, we say the sequence diverges.
But we also have the following definition:
($1$) Given a sequence $x_n$, we say $\lim x_n= \infty$ if $\forall A \in \mathbb{R}$ there is a $N \in \mathbb{N}$ such that $n > N \implies x_n> A$.
Note that this is a slight abuse of notation. The sequence $x_n$ above, BY DEFINITION, does not converge. But we say $\lim x_n= \infty$, because it makes sense. To be completely honest, we should write something different, like $L ~x_n= \infty$
But note that, according to our topology, we have that the definition of $L ~x_n= \infty$ is in fact the definition of $\lim x_n= \infty$. In fact, ($1$) is precisely telling: For all neighbourhoods $V$ of infinity, there exists an $N$ such that $n > N \implies x_n \in V$. So, $x_n$ CONVERGES, and REALLY CONVERGES to $\infty$.
We come to our first proposition:
Proposition: $\displaystyle \overline{\mathbb{R}}$ is compact.
Proof: Take an open cover $V_i$ of $\displaystyle \overline{\mathbb{R}}$. Choose a $V_{i_1}$ such that it contains $+\infty$, and a $V_{i_2}$ such that it contains $-\infty$. They contain a set of the form $(b,\infty]$ and $[-\infty, a)$ respectively, so the rest of the $V_i$ should cover $[a,b]$, which is contained in the complement of those sets. But, by the Heine-Borel Theorem, $[a,b]$ is compact. Hence, there is a finite subcover of $V_i$ that covers $[a,b]$. So, this finite subcover, together with $V_{i_1}$ and $V_{i_2}$ covers $\displaystyle \overline{\mathbb{R}}$. So, we arrived at a finite subcover for $\displaystyle \overline{\mathbb{R}}$. $\blacksquare$.
Corollary: Every sequence in $\displaystyle \overline{\mathbb{R}}$ has a convergent subsequence.
Note the analogy between bolzano-weierstrass theorem and the corollary above. Bolzano-weierstrass says every bounded sequence has a convergent subsequence.
We arrive now at a result that does not involve $\displaystyle \overline{\mathbb{R}}$ at first sight:
Proposition: Let $f:[0,\infty) \rightarrow \mathbb{R}$ be a continuous function such that $\displaystyle \lim _{x \rightarrow \infty}f(x) =L$, and $L<f(0)$. Then, $f$ has a maximum.
Proof: Define $\overline{f} :[0,\infty] \rightarrow \mathbb{R}$ as $f(x)$ if $x \in [0,\infty ) $ and $L$ if $x=\infty$. Since $\displaystyle \lim _{x \rightarrow \infty} f(x)=L$, $\overline{f}$ is continuous in $[0,\infty]$. Since $[0,\infty]$ is closed (not proved, but easily seen to be true) and $\displaystyle \overline{\mathbb{R}}$ is compact, $[0,\infty]$ is compact. Hence, $\overline{f}$ reaches a maximum on $[0,\infty]$. This maximum cannot be in $\infty$, since $f(0)>f(\infty)$. Hence, this maximum must be achieved in $[0,\infty)$. $\blacksquare$
Note somethings in the previous demonstration:
First, $0$ has nothing special. If there was any other place where $f$ was greater than $L$, it would be enough.
Secondly, this requirement (that $f(0)>L$) is just to guarantee that the maximum is in $[0,\infty)$ and not in $[0,\infty]$. In fact, there is always a maximum in $[0,\infty]$. The problem is, sometimes the maximum can be achieved at infinity. Draw an example of this (any monotonic increasing bounded function will do!).
We conclude by sketching the proof of the following theorem:
Theorem: A continuous bijective function $f$ on an interval has a continuous inverse.
Sketch of Proof: If the interval is of the form $[a,b]$, it is compact, and we are done.
If the interval is of the form $[a,b)$, since $f$ is continuous and bijective, it is monotonic (by the intermediate value theorem), so $\displaystyle \lim_{x \rightarrow b}f(x)$ exists (it can be $\infty$, no problem!). Pass to the extension $\overline{f}$ of $f$ on $[a,b]$. It is continuous. Hence, since $[a,b]$ is compact, the inverse is continuous. Restrict the inverse by taking away $\overline{f}(b)$. This is precisely the inverse of $f$. The rest is analogous. $\blacksquare$.