Reminder: For $Q$, a refinement of $P$, $L_f(P) \leq L_f(Q) \leq U_f(Q) \leq U_f(P)$.
Lemma: Let $f : I \to \mathbb{R}$ be a bounded function. If $P_1$ and $P_2$ are 2 partitions of $I$, then $L_f(P_1) \leq L_f(P_2)$.
Proof: If $P_1$ and $P_2$ are partitions of $I$, then $P_1 \cup P_2 = Q$ is a refinement of both $P_1$ and $P_2$. So by a previous lemma, $L_f(P_1) \leq L_f(Q) \leq U_f(Q) \leq U_f(P_2)$. $\blacksquare$
Definition: Let $f : I \to \mathbb{R}$ be a bounded function. We define the lower integral of $f$ on $I$, denotes
$$ L(f) = \sup\{ L_f(P_1) : P_1 \text{ is a partition of }I \} $$
Similarly, we define the upper integral, denoted
$$ U(f) = \inf\{ U_f(P_2) : P_2 \text{ is a partition of }I \} $$
Since $f$ is bounded, let $m = \inf\{ f(x) : x \in I \}$ and $M = \sup\{ f(x) : x \in I \}$. Then if $I = [a,b]$:
$$ m(b-a) \leq L_f(P) \leq U_f(P) \leq M(b-a) $$
Theorem: Let $f : I \to \mathbb{R}$ be a bounded function. Then the lower integral $L(f)$ and the upper integral $U(f)$ exist and
$$ L(f) \leq U(f) $$
Proof: From the previous lemma, if $P_1$ and $P_2$ are partitions of $I$, then $L_f(P_1) \leq U_f(P_2)$, i.e. the set $\{U_f(P_1) : P_1 \text{ is a partition of } I\}$ is bounded above by $U_f(P_2)$. Thus
$$ L(f) = \sup\{U_f(P_1) : P_1 \text{ is a partition of } I\} $$
exists by least upper bound axiom. Note that $L(f) \leq U_f(P_2)$ for any partition $P_2$ of $I$.
Again, $\{U_f(P_2) : P_2 \text{ is a partition of } I\}$ is bounded below. Thus
$$ U(f) = \inf\{U_f(P_2) : P_2 \text{ is a partition of } I\} $$
exists and $L(f) \leq U(f)$. $\blacksquare$
Definition: Let $I = [a,b]$ and $f : I \to \mathbb{R}$ be bounded on $I$. $f$ is said to be Riemann integrable if $L(f) = U(f)$. In this case, the Riemann integral of $f$ over $I$ is defined to be the value $L(f) = U(f)$ and is denoted
$$ \int_a^b f \quad \text{or} \quad \int_a^b f(x) dx $$
In addition, we define
$$ \int_a^a = 0 \quad \text{and} \quad \int_a^b f = -\int_b^a f $$
Let's look at en example:
$f(x) = x$ is Riemann integrable on $[0,1]$.
Let $P = \{0, \frac{1}{n}, \frac{2}{n}, \ldots, 1\}$. The function $f(x)$ is increasing, thus$$ \inf\{f(x) : x \in [x_{k-1}, x_k]\} = f(x_{k-1}) = x_{k_1} $$
Hence
$$ L_f(P) = \sum_{i=1}^n \frac{i-1}{n}\left(\frac{i}{n} - \frac{i-1}{n}\right) = \sum_{i=1}^n \frac{i-1}{n^2} = \frac{1}{n^2}\sum_{i=1}^n i - 1 = \sum_{i=0}^{n-1}i = \sum_{i=1}^{n-1}i = \frac{1}{n^2}\frac{(n-1)n}{2} \frac{1}{2}\frac{n-1}{n} = \frac{1}{2} - \frac{1}{2n} $$
As $1/n \to 0$, $1/ 2n \to 0$ and thus
$$ L(f) = \sup\{L_f(P) : P \text{ is a partition of }I\} \geq \frac{1}{2} $$
We can show in a similar way that $U(f) \leq \frac{1}{2}$ so that $\frac{1}{2} \leq L(f) \leq U(f) \leq \frac{1}{2}$, and so $L(f) = U(f) = \frac{1}{2}$.
Now let's look at a function that is not Riemann integrable on $[0,1]$. Recall Dirichlet's function, defined as
$$ f(x) = \left\{ \begin{array}{lr} 1 & x \in \mathbb{Q}\\ 0 & x \notin \mathbb{Q} \end{array} \right. $$
$f(x)$ is not integrable on $[0,1]$. Let $P$ be a partition of $[0,1]$. Then no matter how fine the partition,
$$ L_f(P) = \sum_{k=1}^n 0 \cdot (x_k - x_{k-1}) = 0 $$
but
$$ U_f(P) = \sum_{k=1}^n 1 \cdot (x_k - x_{k-1}) = 1 $$