How Counterspells Work
To use a counterspell, you must select an opponent as the target of the counterspell. You do this by choosing the ready action. In doing so, you elect to wait to complete your action until your opponent tries to cast a spell. (You may still move your speed, since ready is a standard action.)
If the target of your counterspell tries to cast a spell, make a Spellcraft check (DC 15 + the spell’s level). This check is a free action. If the check succeeds, you correctly identify the opponent’s spell and can attempt to counter it. If the check fails, you can’t do either of these things.
To complete the action, you must then cast the correct spell. As a general rule, a spell can only counter itself. If you are able to cast the same spell and you have it prepared (if you prepare spells), you cast 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.