Credit ratings are typically used by all kinds of investors to price debts and bonds issued by companies. While they are not necessarily relevant for stock investors, having a basic understanding of a company’s credit rating and how it’s changed—and why—is also crucial for investing in a company’s stock. That’s because equity, especially common stock, is ranked below debt in a corporate structure. So if a company is in trouble, as you can see by its credit rating, that could be a leading indicator of falling value for a stock.

how do credit ratings work? A complicated mixture of quantitative and qualitative data is collected by ratings agencies to produce a score that is then given to companies, countries, and municipalities. Different firms use different ratings scales, with the big three—Standard & Poor’s, Moody’s, and Fitch Ratings—producing the standard ratings most analysts use.

The scales can be seen in the following chart:

As you can see, ratings are divided into two primary categories, with “investment grade” being given to higher ratings and “junk” being given to lower ratings. “Junk” can also be referred to as “high yield” or “speculative” debt, since these debt issuers are much closer to default or are in poorer financial health than investment-grade issuers. The higher the rating, typically, the lower the interest rate on the debt. This is why companies and countries typically try to keep the highest rating they possibly can, and why a debt downgrade lowers pre-existing debt values (because newly issued debt will have a higher yield) and puts the company at further risk of insolvency (because their debt will get more expensive to service).

Note that there are also further gradations between “Prime” debt, which is the safest and is seen as almost risk free, and “in default,” which is debt where the issuer has failed to make a payment and may be at risk of bankruptcy.

Different funds and investors will use different types of rated debt in different ways. Typically, a credit investor will create a portfolio of mixed debts, from investment grade to junk, to create a balanced portfolio with a higher yield than you’d get from just AAA-rated debt and less risk than you’d get from just DDD-rated debt.

The magic in this work is in discovering which junk debt is about to be upgraded (thus rising in price) or which is mispriced because the ratings agencies have “missed” something. That “miss” usually relates to something qualitative and difficult to define or articulate. But investors and analysts who discover these errors can make very large returns in a relative short period of time. Wall Street is full of stories of people buying distressed debt at 80% discounts who then make tremendous profits because of a turnaround that causes the debt to get upgraded significantly.

If you dig a little deeper and learn how debt ratings work, you’ll see a lot of opportunities for errors. That’s where credit analysts make tremendous profits for themselves and clients—and is also a rare opportunity to take advantage of market inefficiencies that are almost entirely gone from the publicly traded stock market.