Its simple, (but my English may lack some words, and others here might explain to you in better words), I wil try.
If you think of a wind indicator, Wind vane, on top of a Church, it allways points to where the wind is blowing. This is because its built so that a larger flat vertical portion of it is acting as a "wing", and has a tendency to be "blown" with the wind.
If you now translate that to a boat, and use more or less sail behind the mast (pivot point, almost), by pulling the sheets and doing other trims to make the sail more efficient, you can make the boat point into the wind and away from it.
That is it!!! Simple said, hard to do WELL. And as Tartan said, depends on the boat, I say depends on the fingers of the man playing guitar!!! Most have a guitar but only few make it sound good!!