Over the past two decades, we've witnessed big changes to how the average person invests in the stock market. Essentially gone are the days of having to phone your broker to buy stock. Instead, investors today can simply point and click their way to a diversified portfolio. The same can be said for company financials and news stories, which are at investors' fingertips thanks to the Internet.

Perhaps the biggest consequence of these technological improvements is that completing a trade has gotten cheaper. Most brokerage firms these days charge their clients between $4.95 and $9.99 to trade, with many dangling a rather large carrot to attract active traders and new clients.

For instance, Charles Schwab (NYSE:SCHW), which is best known for attracting more affluent clientele, is offering 500 commission-free trades within a calendar year, including check-in sessions with a trading coach, if you deposit $50,000 or more into a new account. For investors with less to deposit, NerdWallet highlighted TradeKing as a top account promotion choice. On top of its already low $4.95 commission per trade, a $5,000 deposit nets new clients $1,000 in free trade commissions.

Image source: Getty Images.

This brokerage fee could wipe you out

While brokerage fees are often inconsequential to the long-term investor given that high-quality stocks tend to appreciate in value over the long run, there is one fee that has the potential to put a serious dent in your retirement nest egg if you aren't paying close attention. Ladies and gentlemen, I give you the hard-to-borrow fee.

Breaking things down to the simplest level, investors have two choices: bet a stock goes up or that it goes down. If you think a company is worth more than its current valuation, you purchase shares of common stock for that company. If, however, you believe it to be worth far less than its current valuation, you can do what's known as short-selling a stock.

In short-selling, your brokerage firm will sell shares of the stock in question you want to bet against and credit your account with the proceeds. In order to close your short position, you'll need to purchase an equal number of shares of the stock in the future, which is known as "buy to cover." If the stock drops in value, you make money, and if it rises, you'll lose money.

On paper, it sounds pretty simple (basically buying and selling in reverse), but there are a few little intricacies that can wallop investors if they aren't prepared. For example, if you buy a stock and it goes bankrupt, the worst you can do is lose 100% of your investment and not a cent more, assuming you didn't buy it on margin (i.e., borrowed money from your broker). Your gains, though, are limitless. When shorting a stock, the reverse is true; your losses are limitless and your gains are capped at 100%.

Additionally, you don't need a margin account to buy and sell stocks. However, if you want to short-sell, you'll need to have access to margin. Since you're accessing borrowed money from your broker, you'll pay interest on these funds, usually to the tune of 7% to 10% per year, depending on the broker and your level of trading activity. If the Federal Reserve starts raising lending rates, then margin borrowing rates could rise, too.

Image source: Getty Images.

Why the hard-to-borrow fee is so scary

The hard-to-borrow fee is the scariest fee of all. Just as it sounds, it is attached by brokerages to securities where there is minimal liquidity or shares left to sell short. Remember that in order for someone to sell shares short, someone else also has to be long that stock. This hard-to-borrow fee is based on the value of your short position and the borrowing rate for that security, and is charged on a daily basis. Just how high can this annualized fee be? Let's take a look at a personal example.

In late April I was tinkering with the idea of shorting MannKind (NASDAQ:56400P706), a biotechnology company that's marketing inhaled diabetes medication Afrezza. Keeping things simple here, my contention was that MannKind would run out of money and file for bankruptcy well before it figured out how to turn Afrezza around. Having had its marketing partner, Sanofi, walk away from its licensing deal on the contention that Afrezza wasn't economically viable, my conclusion was that short-selling MannKind and paying roughly 8% annual interest on my short position would still net a nice return. Only there was a problem... a big problem.

Image by author from personal brokerage account.

As you can see, my brokerage firm considered MannKind to be a hard-to-borrow security, which made getting short shares actually impossible for more than a week. However, on April 25 short shares became available if I wanted them. The catch? How about an annualized hard-to-borrow rate of 99%! In other words, unless I had a crystal ball or time machine handy and somehow knew that MannKind was going to go bankrupt within the next few months, I was going to hand over the entire value of my short position in interest to my brokerage firm over the course of the next year.

Now, understand that this isn't my brokerage firm trying to stick it to me in any way. Hard-to-borrow fees are completely based on supply and demand, and this usurious interest rate essentially tells me that there was huge demand for short shares of MannKind and veritably no supply. Needless to say, I never wound up committing to the order.

But, if you're not careful, you could wind up being hit with hard-to-borrow fees as well. The example I've used above is pretty easy to spot, as your broker will be upfront with you about charging a hard-to-borrow fee if you're shorting a stock. However, stocks you are currently short can become hard to borrow after the fact, and you could then become subject to the fee.

As yet another example, I made a bet against Tesla Motors (NASDAQ:TSLA) last year with the thinking that Tesla's new product introductions would be delayed yet again. After holding my short shares for months, a message came into my brokerage inbox alerting me that Tesla had become a hard-to-borrow stock, and a 0.25% hard-to-borrow fee would be attached to my position. I didn't think much of it then, but within a matter of two weeks the hard-to-borrow rate had changed no fewer than five times and was now up to 3%. These fees were starting to gobble up any chances I had to turn a profit. Thankfully, I was lucky enough to exit my position with a nominal profit during the markets' swoon in February, but it served as a good learning lesson that just because you didn't short a hard-to-borrow stock initially, it doesn't mean it can't become hard-to-borrow at the click of a button.

So if you're going to consider short-selling, you need to pay very close attention to the fees attached to the stock you're betting against, because if you don't, a nasty surprise could await.