Vsync stands for vertical synchronization. Its purpose is to prevent an occurrence known as "tearing" in games.
This is done by locking a game's framerate to the attached monitor's vertical refresh rate. So, for example, you have a monitor that refreshes at 60Hz (60 times per second). Enabling vsync will lock your FPS at 60. If your graphics card cannot maintain 60FPS, the framerate is dropped to 30FPS, the next lowest factor of 60. If it drops below 30, it will be locked at 20 and so on.
Factors of 60: 60, 30, 20, 15, 12, 10, 6, 5, 4, 3, 2, 1
The reason it must be a factor of 60 is due to the way a monitor refreshes itself. When vsync is enabled, the framebuffer updates at the same rate at the monitor's refresh - in other words, the framebuffer is updated every time the monitor refreshes. When vsync is off, the framebuffer can be updated in the middle of a refresh, as seen in the following illustrations:
Vsync OFF
Vsync ON
If the FPS is locked at 30, the monitor will refresh twice before the framebuffer is updated. If locked at 20, it will refresh three times before the framebuffer is updated. When the framebuffer is updated mid-refresh, it can cause tearing when there is movement on the screen. This is caused by a difference of position in the two frames, creating a "tear" in the image. This can be seen in this illustration:
Vsync OFF
Therefore, vsync can lend to better image quality, by helping to smooth the display of moving imagery.
When do I want to enable vsync?
Vsync is best enabled when you want the best image quality and the game can maintain at least 30FPS minimum on single player or 60FPS minimum on multiplayer.
When do I not want to enable vsync?
When the game cannot maintain 30/60 FPS minimum, or your are benchmarking, vsync is best left off. Sudden transitions between 60 and 30 FPS or between 30 and 20 may be found irritating by some users.