How to be sure that we can span all the periodic functions with a Fourier series? The set of functions $$B = \left\{\frac{1}{\sqrt{2}}, \cos\left(\frac{2\pi n t}{T}\right) \mid n \in \mathbb{N}, \sin\left(\frac{2\pi n t}{T}\right) \mid n \in \mathbb{N} \right\}$$ is a set of othonormal vectors with the scalar product $\langle\ f,g\rangle =\frac{2}{T}\int_{0}^{T} f(t)g(t) \,dt $.
My question is how can we be sure that this set of vector is a basis for all possible $T$-periodic function? Why can't we find other functions orthonormal to the vectors in $B$?
My point with this question is to understand why Fourier said that all real $T$-periodic function can be written as a combination of the vectors in $B$. It is clear that once you have shown that $B$ is a basis for all these functions, then of course you can write any of these functions in the basis $B$.
I would accept a non-rigourous explanation, if it makes intuitively sense. Please try (if possible) to explain the concepts intuitively rather than with complicated mathematical terms.
 A: To simplify notation let me use $2\pi$ periodic functions and set $S^1={\Bbb R}/ 2\pi {\Bbb Z}$.
It is difficult to show the result directly using $L^2(S^1)$ functions. Instead you could first consider a dense subspace of smooth functions. You will need to know e.g. that $C^2(S^1)$ functions are dense in $L^2(S^1)$. Now, if $f$ is a periodic $C^2$ function then its Fourier-series converges uniformly to the function itself.
Here are the steps in a proof: Let $a_k$, $k\geq 0$ and $b_k$, $k\geq 1$ denote the respective Fourier coefficients. The $n$'th partial sum is then given by
$$ f_n(x) = \frac12 a_0 + \sum_{k=1}^n (a_k \cos (kx) + b_k \sin(kx) ) = 
  \frac{1}{2\pi} \int_0^{2\pi} f(t)\left[ \frac12 + \sum_{k=1}^n \cos k(x-t) \right] dt $$
which after a change of variables $t=x+u$ leads to
$$ f_n(x) = \frac{1}{2\pi} \int_{-\pi}^\pi  f(x+u) \frac{\sin \, (n+\frac12)u}{\sin  \, \frac12 u} du$$
and then
$$ f_n(x)-f(x)= \frac{1}{2\pi} \int_{-\pi}^\pi  \frac{f(x+u)-f(x)}{\sin  \, \frac12 u}  \sin \left((n+\frac12)u \right)du.$$
The fraction in the last integral is uniformly continuous (in fact $C^1$) in $x$ and $u$ which implies that the integral goes uniformly to zero as $n\to +\infty$. Thus the trigonometric polynomial $f_n\to f$ uniformly.
Approximating $L^2$ functions by $C^2$ functions,  the rest follows. For example any $L^2$ function which is orthogonal to all of the above basis elements must equal zero a.e., Parseval's identity etc...
EDIT: With hints for the above calculations:
$$ \cos(kx-kt)= \cos(kx)\cos(kt) + \sin(kx)\sin(kt).$$
$$\sin (\frac{u}{2}) \left(\frac12 + \sum_{k=1}^n \cos(ku)\right) = \frac12 \left( \sin(\frac{u}2) + \sum_{k=1}^n (\sin(k+\frac12)u - \sin(k-\frac12)u \right)$$
For a periodic $C^1$ function $\phi$ (integration by parts):
$$\int_{-\pi}^\pi \phi(t)\sin\left((n+\frac12)u\right)du = \int_{-\pi}^\pi \phi'(t) \frac{\cos\left((n+\frac12)u\right)}{n+\frac12} \; du $$
A: I recommend reading Chapter 4 of Walter Rudin's book Real and Complex Analysis for a concise, rigorous and step by step proof of the completeness of trigonometric functions. Theorem 4.24 and 4.25 (in 3rd edition) are exactly what you are looking for. For the sake of brevity, I will transcribe a part of the text:
4.24 The Completeness of the Trigonometric System Theorem 4.18 shows that the maximality (or completeness) of the trigonometric system will be proved as soon as we can show that the set of all trigonometric polynomials is dense in $\mathcal L^2(T)$. Since $C(T)$ is dense in $\mathcal L^2(T)$, by Theorem 3.14 (note that $T$ is compact), it suffices to show that to every $f \in C(T)$ and to every $\epsilon > 0$ there is a trigonometric polynomial $P$ such that $\left\lVert f - P\right\rVert_2 < \epsilon$. Since $\left\lVert g\right\rVert_2 \le \left\lVert g\right\rVert_\infty$ for every $g \in C(T)$, the estimate $\left\lVert f - P\right\rVert_2 < \epsilon$ will follow from $\left\lVert f - P\right\rVert_\infty < \epsilon$, and it is this estimate which we shall prove.
Please refer to p. 90 of the 3rd ed.
4.25 Theorem If $f \in C(T)$ and $\epsilon > 0$, there is a trigonometric polynomial $P$ such that
$$|f(t) - P(t) | < \epsilon$$
for every real $t$.
A: $f_{FT}(x)=\sum_n a_n cos(nx)+b_n sin(nx) = \sum_n \int f(t)cos(nt) cos(nx) dt +\int f(t)sin(nt) sin(nx) dt $
$= \int f(t) (\sum_n cos(nt) cos(nx) + sin(nt) sin(nx)) dt $ 
$= \int f(t) (\sum_n cos(n(t-x)) dt $ 
$= \int f(t) Re(\sum_{n} exp(in(t-x)))  dt $ 
$= \int f(t) \delta(t-x)  dt $ 
$= f(x) $
for the last equality refer: http://web.mit.edu/8.03-esg/watkins/8.03/deltf.pdf
There are conditions in which i can swap integral and infinite summation. So i am assuming $f$ satisfies all those conditions.
Edited:
Now coming to ur question: Can all periodic functions be written as fourier series. This boils down to the fact does the proof i gave works for all possible periodic functions. Answer is No. Read Section 1.1 : http://math.iisc.ernet.in/~veluma/fourier.pdf where the author mentions that it is possible to construct continuous periofic function whose fourier series differs from function at a particular point. But all hope is not lost. See theorem 1.1 in the same link where the author mentions that the set of all fourier expansions or the space spanned by the basis u have given is dense in $C[0,1]$. Hope this helps
A: I think the Stone-Weierstrass Theorem can be applied to prove that the $\cos(2\pi mt/T)$ and $\sin(2\pi nt/T)$ trig functions have as their $L^2$-Hilbert-span the whole $L^2$ space of periodic functions on $[0,T]$, where $S^1$ is viewed as $[0,T]$ with endpoints identified.
As a reference, see in Terry Tao's analysis book An Epsilon of Room, Volume I (an online version is available at his blog post here) the comment following the statement of Theorem 1.12.4 (Plancherel Theorem for compact Abelian groups), specifically the first item about when $G$ is a torus; the case of interest here is when $G$ is $S^1$ (the "1-torus"), since we can view periodic functions on $[0,T]$ as functions on $S^1$. See Theorem 1.10.18 in that book for the Stone-Weierstrass theorem.

Here is an outline of how to apply Stone-Weierstrass to prove that the Hilbert-span of the trig functions $\sin(2\pi mt / T),\cos(2\pi n t,T)$ for $m,n\in\mathbb{Z}$ is all of the $L^2$ space of periodic functions on $[0,T]$.
For convenience, view the $L^2$ space of periodic functions on $[0,T]$ as the space of $L^2$ functions on $S^1$; here $S^1$ is viewed as $[0,T]$ with endpoints identified. Similarly, view the space of periodic continuous functions on $[0,T]$ as the space $C(S^1)$ of continuous functions on $S^1$.
We want to show the trig functions have $L^2$-Hilbert-span equal to all of $L^2(S^1)$.
This means we want to show the set of "countable linear combinations" (with coefficients forming an $\ell^2$, i.e. square-summable, sequence; see Exercise 1.4.18 of Tao's book) of the trig functions is all of $L^2(S^1)$.
To show this spanning property, it suffices to show that the set of finite linear combinations of the trig functions has $L^2$-closure equal to all of $L^2(S^1)$.
Let $\mathcal{A}$ be the set of finite linear combinations of the trigonometric functions $\cos(2\pi mt/T)$ and $\sin(2\pi nt/T)$ for $m,n\in\mathbb{Z}$. Our aim is to show $\mathcal{A}$ is ($L^2$-)dense in $L^2(S^1)$.
This is where Stone-Weierstrass can be used.
The following are the conditions needed for Stone-Weierstrass to be applied.

*

*We can show $\mathcal{A}$ "separates points", i.e. for any two points $t_1,t_2 \in S^1$ with $t_1 \neq t_2$ there is $f \in \mathcal{A}$ with $f(t_1) \neq f(t_2)$.


*We can show $\mathcal{A} \subset C(S^1)$ is a unital subalgebra (also preserved by pointwise complex conjugation, if we allow complex linear combinations) of $C(S^1)$, the set of continuous functions on $S^1$.
Note: that $\mathcal{A} \subset C(S^1)$ is a unital subalgebra means basically that the constant functions are in $\mathcal{A}$ and also $\mathcal{A}$ is preserved by addition and multiplication of functions. (That $\mathcal{A}$ is preserved by multiplication may be easier to see if you use $e^{\pm 2\pi imt/T}$ as an alternative to $\cos(2\pi m t/T),\sin(2\pi m t/T)$, though this would require complex linear combinations; alternatively, one can use the trig addition formulas.)
Now, applying Stone-Weierstrass, we can say $\mathcal{A}$ is dense for the uniform topology in $C(S^1)$, the continuous functions on $S^1$, where $S^1$ is viewed as $[0,T]$ with endpoints identified.
All that remains now is to use the following:

*

*This implies $\mathcal{A}$ is also dense in $C(S^1)$ for the $L^2$ norm; indeed the $L^2$ norm is $\leq$ $\sqrt{T}$ times the $L^\infty$ norm (i.e. uniform norm) on $S^1$, viewed as $[0,T]$ with endpoints identified.

*And $C(S^1)$ is already dense in $L^2(S^1)$ for the $L^2$ norm.
E.g.: $L^2$ functions can be $L^2$-approximated by finite linear combinations of characteristic functions (meaning, functions which are 1 on some measurable subset $E \subset S^1$ and 0 outside that set $E$), which in turn can be $L^2$-approximated by continuous functions in whichever manner.

Then we can conclude $\mathcal{A}$ is $L^2$-dense in $L^2(S^1)$. In other words $\mathcal{A} = \mathrm{finitary}\textrm{-}\mathrm{span}(\{\textrm{trig functions}\})$ has $L^2$-closure equal to all of $L^2(S^1)$. Thus the trig functions indeed $L^2$-Hilbert-span all of $L^2(S^1)$.

Finally, since the above shows that the trig functions are an $L^2$-Hilbert-spanning set for $L^2(S^1)$, and the trig functions are $L^2$-orthonormal which can be proved with some straightforward definite integrals, we may conclude the trig functions are a Hilbert basis for $L^2(S^1)$, viewed alternately as the $L^2$ space of periodic functions on $[0,T]$.
Note: the Fourier series for an $L^2$ function $f$ converges to $f$ only in the $L^2$ sense. I think this may not be a pointwise convergence in general, as has been pointed out in Balaji sb's answer.
