Finding the average of a finite number of values is easy -- just add them up and divide by the number of values. For example, we know that the average of $n$ function values $f(x_1), \ f(x_2), \, \ldots, \, f(x_n)$ is given by
$$\frac{f(x_1) + f(x_2) + \cdots + f(x_n)}{n}$$However, how can one find the average of all of the values a function assumes over an interval? Interestingly, this so-called average value of a function over $[a,b]$ can be expressed in terms of a limit of a Riemann sum, and consequently a definite integral!
Suppose $f$ is a function defined on $[a,b]$ and $a = x_0 \lt x_1 \lt x_2 \lt \cdots \lt x_n = b$ is a regular partition of $[a,b]$.
Let us denote the width of the $i^{th}$ sub-interval by $\displaystyle{\Delta x = \frac{b-a}{n}}$, which means $x_i = a + i\Delta x$.
$$\begin{array}{rcl} \displaystyle{\frac{f(x_1) + f(x_2) + \cdots + f(x_n)}{n}} &=& \displaystyle{\sum_{i=1}^n \frac{f(x_i)}{n}}\\ &=& \displaystyle{\sum_{i=1}^n f(x_i) \frac{\Delta x}{b-a} \quad \quad {\left(\small \textrm{since } \, \frac{1}{n} = \frac{\Delta x}{b-a}\right)}}\\ &=& \displaystyle{\frac{1}{b-a} \sum_{i=1}^n f(x_i) \Delta x} \end{array}$$Note that the sum in the last expression is a Riemann sum. To average all of the function values assumed over $[a,b]$, we simply allow $n$ to increase without bound, recalling
$$\lim_{n \rightarrow \infty} \sum_{i=1}^n f(x_i) \Delta x = \int_a^b f(x)\,dx$$Thus, if $f_{avg}$ denotes the aforementioned average value of $f$ over $[a,b]$, we have
$$f_{avg} = \frac{1}{b-a} \int_a^b f(x)\,dx$$