How is layered navigation implemented?

What is the code flow for layered navigation, how does it work?