Simply put, the Dispel Magic spell can be used to interrupt another spellcaster that is in the process of completing a spell of their own. Unlike an attempt to dispel a potion or active effect, a mage that is struck by a Dispel Magic while in the process of casting a spell automatically fails and loses the spell. The Dispel Magic still has its usual effects, as well - destroying potions, removing protections, and so on.
There are a few ways that a counterspell might go down in combat:
- By holding an action: This is the easiest way to cast a counterspell - success is virtually guaranteed. In this instance, you hold an action before the target begins casting. As soon as he begins to cast his spell, you can immediately take your held action to counterspell him - regardless of what he rolls for initiative or how long his spell takes to cast.
- By winning initiative: If you don't have a full round's warning but you know he is going to cast a spell, you can attempt to cast Dispel Magic in the same round as your target. In this case, you succeed only if you win initiative - taking your casting time into account. This means, for example, that if your target is casting Magic Missile (casting time of 1), you'd need to win initiative by at least 2, since Dispel Magic has a casting time of 3.
A successful Spellcraft check will allow you to figure out what spell is being cast before you attempt to dispel it; this can inform the decision whether or not to waste a Dispel Magic on it.