For example, a bank sues a customer for an unpaid debt, while the customer counterclaims (sues back) against the bank for fraud in procuring the debt. The court will sort out the different claims in one lawsuit (unless the claims are severed).
Counterclaims are either compulsory or permissive. If the counterclaim is permissive, it may be brought, but no rights are waived if it is not. If the counterclaim is mandatory, it must be brought in the current action or it is waived. Under the United States Federal Rules of Civil Procedure, a counterclaim is compulsory if it involves only the parties currently part of the suit, and is from the same transaction that the original suit is based on. Federal Rule of Civil Procedure 13(a). http://cfr.law.cornell.edu/rules/frcp/Rule13.htm