Stencil Buffer

Could someome explain me how does the stencil buffer works?
or at least show me a good link to a tutorial?

Search this board for Stencil Buffer, you should be able to find something, yours is a fairly common question.