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 upon which the original suit is based.