Is it the securities lender? If so, do they discriminate on the stocks they are willing to lend, or will they lend any stock?
It seems like the business of lending securities would be extremely risky.
The correct answer to this question is: the person who the short sells the stock to.
Here's why this is the case. Say we have A, who owns the stock and lends it to B, who then sells it short to C. After this the price drops and B buys the stock back from D and returns it to A.
The outcome for A is neutral. Typically stock that is sold short must be held in a margin account; the broker can borrow the shares from A, collect interest from B, and A has no idea this is going on, because the shares are held in a street name (the brokerage's name) and not A. If A decides during this period to sell, the transaction will occur immediately, and the brokerage must shuffle things around so the shares can be delivered. If this is going to be difficult then the cost for borrowing shares becomes very high.
The outcome for B is obviously a profit: they sold high first and bought (back) low afterwards.
This leaves either C or D as having lost this money. Why isn't it D?
One way of looking at this is that the profit to B comes from the difference in the price from selling to C and buying from D. D is sitting on the low end, and thus is not paying out the profit. D bought low, compared to C and this did not lose any money, so C is the only remaining choice.
Another way of looking at it is that C actually "lost" all the money when purchasing the stock. After all, all the money went directly from C to B. In return, C got some stock with the hope that in the future C could sell it for more than was paid for it. But C literally gave the money to B, so how could anybody else "pay" the loss?
Another way of looking at it is that C buys a stock which then decreases in value. C is thus now sitting on a loss. The fact that it is currently only a paper loss makes this less obvious; if the stock were to recover to the price C bought at, one might conclude that C did not lose the money to B. However, in this same scenario, D also makes money that C could have made had C bought at D's price, proving that C really did lose the money to B.
The final way of seeing that the answer is C is to consider what happens when somebody sells a stock which they already hold but the price goes up; who did they lose out on the gain to? The person again is; who bought their stock. The person would buys the stock is always the person who the gain goes to when the price appreciates, or the loss comes out of if the price falls.
Nobody; or at least, no individual counterparty.
Let’s use (mostly) @Michael’s labels of borrowing securities from beneficial owner A via broker B, sell high to C and buy back low from D. Note that in this answer, B refers to the broker rather than the borrower.
A: starts with the securities and ends with the same. The broker makes good if A wants to trade while the securities are on loan.
B: charges interest for the loan, so makes a profit. B may sustain a loss if A sells during the loan and B can not recover the securities from the borrower, but this is not directly a loss due to the borrower’s profit.
C: willing buyer. The price might go up before it comes down, or it might go up later. C could sell at either opportunity, so the borrower’s profit isn’t directly tied to C.
D: willing seller (at least, not necessarily a forced sale). D might have bought even lower beforehand, so the borrower’s profit isn’t always/necessarily funded by a loss here.
The situation is like hiring machinery to produce goods for sale. The hirer can make a profit without anyone making a loss.
Alternatively, consider the situation where you bought low first and sold high later. A, B, C and D have exactly the same profit/loss profiles. Assuming all are willing parties to the transactions, there is no single party that sustains a loss to produce your gain.
The real loss comes from C and D, taken together.
Philosophically, you could perhaps say that it is the underlying security itself that sustains the loss. Selling a security exerts a downward pressure on its price and contributes to the profit gained when it is repurchased. The underlying company loses market capitalisation by the price drop, but it is not a crystallised loss on the basis of being the underlying company.
Michael gave a good answer describing the transaction but I wanted to follow up on your questions about the lender.
First, the lender does charge interest on the borrowed securities. The amount of interest can vary based on a number of factors, such as who is borrowing, how much are they borrowing, and what stock are they trying to borrow.
Occasionally when you are trying to short a stock you will get an error that it is hard to borrow. This could be for a few reasons, such as there are already a large amount of people who have shorted your broker's shares, or your broker never acquired the shares to begin with (which usually only happens on very small stocks). In both cases the broker/lender doesnt have enough shares and may be unwilling to get more. In that way they are discriminating on what they lend. If a company is about to go bankrupt and a lender doesnt have any more shares to lend out, it is unlikely they will purchase more as they stand to lose a lot and gain very little.
It might seem like lending is a risky business but think of it as occurring over decades and not months. General Motors had been around for 100 years before it went bankrupt, so any lender who had owned and been lending out GM shares for a fraction of that time likely still profited.
Also this is all very simplified. JoeTaxpayer alluded to this in the comments but in actuality who is lending stock or even who owns stock is much more complicated and probably doesnt need to be explained here. I just wanted to show in this over-simplified explanation that lending is not as risky as it may first seem.
Between the time the borrowed shares (say N shares) are sold and the time they are bought to cover, the number of long shares held by other investors is N greater than it would be "otherwise" -- i.e., than it would be in the baseline scenario where the short wasn't performed.
Which investors exactly (as a function of time) hold the "extra" N shares is a complex counterfactual question of market dynamics. (It's not just about trades that happened that otherwise wouldn't have happened, but also about trades that didn't happen that otherwise would have happened.)
But whoever the investors holding the extra N shares are, if the stock declines by $A during this period, they have a collective loss of $A x N compared to the baseline -- which matches the profit made by the short seller.
Not really. The lender is not buying the stock back at a lower price. Remember, he already owns it, so he need not buy it again.
The person losing is the one from whom the short seller buys back the stock, provided that person bought the stock at higher price.
So if B borrowed from A(lender) and sold it to C, and later B purchased it back from C at a lower price, then B made profit, C made loss and A made nothing .