As explained in the article on apparent wind, a boat's forward motion creates a corresponding head wind of the same strength in the opposite direction.
The drawing below shows the vector operations and resulting calculations for sailing upwind.