A "riffle shuffle" is the classic way to randomize the order of a deck of cards. You split the deck in half and then "riffle" the cards to interleave the two halves. Astonishingly, some people can perform a "perfect" shuffle, where the riffling precisely alternates between cards from one half of the deck and the other. A weird fact is that doing eight perfect shuffles in a row returns the deck to its original order.
I'd heard of this fact, but wanted to see it for myself. Since I can't do a perfect shuffle I made this visualization. Take a look, then read more below about how this all works.
Why this happens: A perfect riffle shuffle turns out to have an especially simple mathematical description. To begin with, notice the bottom card always stays on the bottom, so we can ignore it in our analysis. For the other 51 cards, the shuffles takes a beautifully simple form. Thinking of the card position as points on a circle, the riffle stretches the circle and wraps it around twice. That is, numbering positions from 0 to 50, a riffle takes a card at position x to the position 2x (mod 51). Touch the diagrams below to see this at work.
The fact that it only takes eight shuffles really is lucky. If you added two jokers to the deck, or started your interleaving from the bottom half of the deck rather than the top, it would take 52 shuffles to return to the original order. And if you picked a random permutation as your shuffle, it could take thousands. Exploring and generalizing the effects of riffle variations leads to beautiful mathematics: from combinatorics to group theory to famously unanswered questions.