What a state machine is
A counter steps through a fixed sequence. A finite state machine (FSM) chooses its next step based on inputs, which makes it the control logic of nearly every digital system: vending machines, traffic lights, communication protocols and the control unit of a processor.
Every FSM has three parts: state registers remembering where it is, next-state logic deciding where to go, and output logic. The state tells you what the machine needs to remember about the past, and nothing more.