Expanding on what Ken said, and using the encoder wheel he linked to (note that there are many different types of encoder wheels)....
Imagine that you have two sensors , A and B, that are placed on the radius of the encoder such that A is over the inner encoded band and B is over the outer. The way that the encoder wheel is laid out, if sampled properly, A and B will never change states at the same time.
Knowing this, the following table describes the valid state transitions. (assume 0 = dark and 1 = light)
Code:
Previous AB Current AB
00 01 - Counterclockwise
00 10 - Clockwise
01 11 - Counterclockwise
01 00 - Clockwise
11 10 - Counterclockwise
11 01 - Clockwise
10 00 - Counterclockwise
10 11 - Clockwise
Transitions such as 00->11, 01->10, 10->01, 11->00 tell you that there was rotation, but you don't know which direction the rotation was.
So to answer your original question, you have 4 states because there are 4 states that your encoder is reporting.
