I understand that the bid-ask spread is the difference between the price a buyer is willing to pay and the price a seller is willing to take for an asset. I also understand that this difference goes to the "market maker". Who is this market maker? To me it seems like this would be the exchange. Is it ever the case that the market maker is the exchange? If not, who is it?
Joke warning: These days, it seems that rogue trading programs are the big market makers (this concludes the joke)
Historically, exchange members were market makers. One or more members guaranteed a market in a particular stock, and would buy whatever you wanted to sell (or vice-versa). In a balanced market -- one where there were an equal number of buyers and sellers -- the spread was indeed profit for them. To make this work, market makers need an enormous amount of liquidity (ability to hold an inventory of stocks) to deal with temporary imbalances. And a day like October 29, 1929, can make that liquidity evaporate.
I say "historically," because I don't think that any stock market works this way today (I was discussing this very topic with a colleague last week, went to Wikipedia to look at the structure of the NYSE, and saw no mention of exchange members as market makers -- in fact, it appears that the NYSE is no longer a member-based exchange).
Instead, today most (all?) trading happens on "electronic crossing networks," where the spread is simply the difference between the highest bid and lowest ask. In a liquid stock, there will be hundreds if not thousands of orders clustered around the "current" price, usually diverging by fractions of a cent. In an illiquid stock, there may be a spread, but eventually one bid will move up or one ask will move down (or new bids will come in). You could claim that an entity with a large block of stock to move takes the role of market maker, but it doesn't have the same meaning as an exchange market maker.
Since there's no entity between the bidder and asker, there's no profit in the spread, just a fee taken by the ECN.
Edit: I think you have a misconception of what the "spread" is. It's simply the difference between the highest bid and the lowest offer. At the instant a trade takes place, the spread is 0: the highest bid equals the lowest offer, and the bidder and seller exchange shares for money. As soon as that trade is completed, the spread re-appears. The only way that a trade happens is if buyer and seller agree on price.
The traditional market maker is simply an entity that has the ability to buy or sell an effectively unlimited number of shares. However, if the market maker sets a price and there are no buyers, then no trade takes place. And if there's another entity willing to sell shares below the market maker's price, then the buyers will go to that entity unless the market's rules forbid it.
A "market maker" is someone that is contractually bound, by the exchange, to provide both bid and ask prices for a given volume (e.g. 5000 shares). A single market maker usually covers many stocks, and a single stock is usually covered by many market makers. The NYSE has "specialists" that are market makers that also performed a few other roles in the management of trading for a stock, and usually a single issue on the NYSE is covered by only one market maker.
Market makers are often middlemen between brokers (ignoring stuff like dark pools, and the fact that brokers will often trade stocks internally among their own clients before going to the exchange).
Historically, the market makers gave up buy/sell discretion in exchange for being the "go-to guys" for anyone wanting to trade in that stock. When you told your broker to buy a stock for you, he didn't hook you up with another retail investor; he went to the market maker. Market makers would also sometimes find investors willing to step in when more liquidity was needed for a security. They were like other floor traders; they hung out on the exchange floors and interacted with traders to buy and sell stocks. Traders came to them when they wanted to buy one of the specialist's issues. There was no public order book; just ticker tape and a quote. It was up to the market maker to maintain that order book.
Since they are effectively forbidden from being one-sided traders in a security, their profit comes from the bid-ask spread. Being the counter-party to almost every trade, they'd make profit from always selling above where they were buying. (Except when the price moved quickly -- the downside to this arrangement.) "The spread goes to the market maker" is just stating that the profit implicit in the spread gets consumed by the market maker.
With the switch to ECNs, the role of the market maker has changed. For example, ForEx trading firms tend to act as market makers to their customers. On ECNs, the invisible, anonymous guy at the other end of most trades is often a market maker, still performing his traditional role. Yet brokers can interact directly with each other now, rather than relying on the market maker's book. With modern online investing and public order books, retail investors might even be trading directly with each other.
Market makers are still out there; in part, they perform a service sold by an Exchange to the companies that choose to be listed on that exchange. That service has changed to helping tamp volatility during normal high-volatility periods (such as at open and close).
I understand that the bid-ask spread is the difference between the price a buyer is willing to pay and the price a seller is willing to take for an asset.
Correct. However the market maker may also be the buyer and or seller of the security.
I also understand that this difference goes to the "market maker".
It is not quite as simple. A market maker (sometimes called the "specialist") makes his money by trading the spread, in that he might bid $5.00 for the security and offer the security for $6.00. If someone desperately wants to sell, they sell their security to the market maker for $5.00. If they desperately want to buy, they buy the security from the market maker for $6.00.
Historically some exchanges (e.g. NYSE) had rules that said that if you wanted to buy a security you had to buy it from the specialist and if you wanted to sell it, you had to sell it to the specialist. This meant the specialist ultimately controlled the price of the security. However now that there are multiple exchanges and many do not give specialists as much control, they are just another participant like everyone else (though many still enjoy rights such as receiving a portion of the trade if their bid or offer is equal to the best bid or offer respectively). Often these rights now are given to special market makers called "Designated Market Makers" or "Primary Market Makers" (each exchange has their own name and rules). In exchange they have to provide quotes to buy and sell for a certain percentage of the day.
Who is this market maker?
Some exchanges list their market makers, while some do not. These are generally proprietary trading firms that specialize in making markets.
To me it seems like this would be the exchange. Is it ever the case that the market maker is the exchange?
It used to be that the market makers would own a 'seat' on the exchange, e.g. they sit in the circular booths on the NYSE floor that you see on TV. The seat would give them an ownership interest in the exchange and they would have a say in how the exchange is run. However over the past few decades with the advent of electronic trading, the market makers cashed out their shares when the exchanges went public or got bought out by other exchanges.