How do rotary encoders work?

How do rotary encoders work?:

#arduino