If $f$ is a periodic function with period $2\pi$, a Fourier series for $f$ is an expansion of the form $$f(x) = \frac{a_0} 2 + \sum_{n = 1}^\infty a_n \cos nx + \sum_{n = 1}^\infty b_n \sin nx .$$
If $f$ is continuously differentiable, a theorem of Dirichlet states that a Fourier expansion exists where the infinite sums converge uniformly to $f$. Under the weaker assumption that $f \in L^2[0,2\pi]$, there exists a Fourier expansion where the infinite sums converge to $f$ in the $L^2$ sense.
The sines and cosines appearing in the Fourier expansion form an orthogonal basis for $L^2[0,2\pi]$. Therefore, a simple way of evaluating the $a_n$ and $b_n$ coefficients is by orthogonal projection, $$a_n = \frac 1 \pi \int_0^{2\pi} f(x) \cos nx\ \mathrm dx, \ \ \ \ \ \ \ \ \ b_n = \frac 1 \pi \int_0^{2\pi} f(x) \sin nx\ \mathrm dx.$$