We write |A| for the cardinality of a finite set A—that is, its number of elements.
Thus, |A1 \cup A2| = |A1| + |A2| − |A1 \cap A2|,
|A1 \cup A2 \cup A3| = |A1| + |A2| + |A3| − (|A1 \cap A2| + |A2 \cap A3| + |A1 \cap A3|) + |A1 \cap A2 \cap A3|, and so on.
This formula is also known as the inclusion–exclusion principle. It is used in counting problems, of which the hat-check problem is a classic example: if the hats belonging to a gathering of n people are randomly distributed, what is the probability that no one leaves with their own hat? Let A*i be the event that person i left with their own hat. Poincaré's sieve formula shows that this probability tends to 1/e* (approximately 36.8%).