Myhill-Nerode Theorem
A language L is regular if and only if it has finitely many equivalence classes under the relation x ≡ y exactly when, for every suffix z, xz belongs to L if and only if yz belongs to L. The number of classes equals the number of states in the minimal deterministic finite automaton recognising L.
Two prefixes are distinguishable when some common suffix makes exactly one resulting string a member of L. A correct DFA must send distinguishable prefixes to different states. By the Pigeonhole Principle, more pairwise distinguishable prefixes than states force an error; infinitely many such prefixes rule out every finite-state recognizer.
For example, in L = {aⁿbⁿ | n ≥ 0}, the prefixes aⁱ and aʲ, for i ≠ j, are distinguished by the suffix bⁱ. There are infinitely many distinguishable prefixes, so L is not regular. A pushdown automaton can recognise it by using its stack to match the counts.
Visual intuition: a state is a memory
Pause a recognizer after it reads a prefix. Its current state determines how it will handle every possible continuation. Two prefixes may share a state only if no continuation can distinguish them.
For the equal-count language above, try appending the same suffix, bb, to two different prefixes:

The different answers prove that a and aa need different states. If the recognizer merged them, it would lose information needed for a correct decision:

The same argument works for arbitrarily many prefixes:
| Prefix | Append this suffix | Result | What it distinguishes |
a | b | ab: accept | Every other prefix consisting only of a’s rejects with this suffix |
aa | bb | aabb: accept | Every other prefix consisting only of a’s rejects with this suffix |
aaa | bbb | aaabbb: accept | Every other prefix consisting only of a’s rejects with this suffix |
| aⁿ | bⁿ | aⁿbⁿ: accept | Every aᵐ with m ≠ n rejects with this suffix |
There are infinitely many pairwise distinguishable prefixes. Any finite collection of states must eventually merge two of them, by the Pigeonhole Principle. Therefore, no DFA can recognise this language exactly.