The second route is the "trade-in." Most dealers almost never pay cash for the amount of money that they offer for trade-in. It's purely a negotiating tactic meant to make a buyer feel better about a (relatively arbitrary) price on a car ("$14k for a 2015 Ford Focus is kind of high, but we really like that we're getting $4k for our 2007 Pontiac Aztek!"). Whenever you work with a dealer, you're almost always getting fleeced. Again, some people enjoy the process as a sort of game or hobby, but you're likely not making a profit unless you're extremely good at it.
EDIT: I read this over and it sounded a little fanboyish. I want to make clear that I've been gone from CarMax for almost 5 years and I don't own stock or have any other financial stake in their success other than some friends who are still employed there. I just think they're a good company (although I didn't love working in IT).