Counterspelling is fairly simple, in concept, but in actual execution, I don't see it done, as often. It depends on the game, the spellcasters, and other factors.
Essentially, there are three ways to cast a counterspell:
1) Use Dispel Magic or Greater Dispel Magic
2) Use a direct polar opposite spell to the one being countered
3) Cast the exact same spell in response to the caster (white noise casting, essentially)
Here's the rub, though: you need to be able to cast the counterspell in reaction to the spell being cast. To do this, you need to either ready an action to cast a counterspell, or have an appropriate spell memorized as a quickened spell.
Then, per the SRD
If the target of the character's counterspell tries to cast a spell, the character makes a Spellcraft check (DC 15 + the spell's level). This check is a free action. If the check succeeds, the character correctly identifies the opponent's spell and can attempt to counter it. (If the check fails, the character can't do either of these things.)
To complete the action, the character must cast the correct spell. As a general rule, a spell can only counter itself. If the character is able to cast the same spell and has it prepared (if the character prepares spells), the character casts it, altering it slightly to create a counterspell effect. If the target is within range, both spells automatically negate each other with no other results.
Counterspelling Metamagic Spells: Metamagic feats are not taken into account when determining whether a spell can be countered.
So here's three quick examples:
1) Mage X casts a Fireball. Cleric Y has been waiting for this, and throws a greater dispelling to attempt to counter it.
2) Mage X casts a Fireball. Mage Z makes a spellcraft roll to identify the spell being cast, and then uses his own memorized Fireball spell to attempt to counter the spell.
3) Mage X casts a Haste spell to speed himself up. Mage Z, expecting this, casts a memorized Slow spell to automatically counter the haste spell.
Get the idea?