Setting up an Animation State Machine

How to set up and play different animations for a 2D character based on different states.