TITLE: How do I exactly project a vector onto a subspace?
QUESTION [49 upvotes]: I am trying to understand how - exactly - I go about projecting a vector onto a subspace.
Now, I know enough about linear algebra to know about projections, dot products, spans, etc etc, so I am not sure if I am reading too much into this, or if this is something that I have missed.
For a class I am taking, the proff is saying that we take a vector, and 'simply project it onto a subspace', (where that subspace is formed from a set of orthogonal basis vectors).
Now, I know that a subspace is really, at the end of the day, just a set of vectors. (That satisfy properties here). I get that part - that its this set of vectors. So, how do I "project a vector on this subspace"?
Am I projecting my one vector, (lets call it a[n]) onto ALL the vectors in this subspace? (What if there is an infinite number of them?)
For further context, the proff was saying that lets say we found a set of basis vectors for a signal, (lets call them b[n] and c[n]) then we would project a[n] onto its signal subspace. We project a[n] onto the signal-subspace formed by b[n] and c[n]. Well, how is this done exactly?..
Thanks in advance, let me know if I can clarify anything!
P.S. I appreciate your help, and I would really like for the clarification to this problem to be somewhat 'concrete' - for example, something that I can show for myself over MATLAB. Analogues using 2-D or 3-D space so that I can visualize what is going on would be very much appreciated as well. 
Thanks again.

REPLY [6 votes]: The projection of the vector is the vector belonging to the subspace that best approximates the former, i.e. such that the (squared) norm of the difference is the smallest.
WLOG take a subspace spanned by three vectors. We minimize for the coordinates $u,v,w$
$$\epsilon=(\vec d-u\vec a-v\vec b-w\vec c)^2.$$
This is achieved by canceling the gradient (factor $2$ omitted),
$$\begin{cases}
\dfrac{d\epsilon}{du}=\vec a\cdot(\vec d-u\vec a-v\vec b-w\vec c)=0,\\
\dfrac{d\epsilon}{dv}=\vec b\cdot(\vec d-u\vec a-v\vec b-w\vec c)=0,\\
\dfrac{d\epsilon}{dw}=\vec c\cdot(\vec d-u\vec a-v\vec b-w\vec c)=0.\\
\end{cases}$$ giving a linear system of three equations in three unknonws.
In the special case that $\vec a,\vec b,\vec c$ form an orthonormal basis, we simply have
$$u=\vec d\cdot\vec a,v=\vec d\cdot\vec b,w=\vec d\cdot\vec c,$$ and the projection is
$$\vec u^*=(\vec d\cdot\vec a)\vec a+(\vec d\cdot\vec b)\vec b+(\vec d\cdot\vec c)\vec c.$$