A stock's price-to-earnings ratio, or P/E ratio, is an expression of how expensive a stock is relative to the profits generated by the underlying company. Because of factors such as risk and growth rate, P/E ratios of different companies often vary considerably. Therefore, while P/E ratios are certainly useful tools in stock analysis, they are just one piece of the puzzle and should be considered along with several other metrics.

What is the P/E ratio?

The P/E ratio is a measurement of how expensive (or cheap) a stock is relative to the profits it generates. To determine a P/E ratio, simply take a stock's current price and divide it by its annual earnings per share. For example, a stock trading for $20 that earns $1 per share would have a P/E ratio of 20.

Stock chart on a computer screen, trending upward.

Image source: Getty Images.

There are a few things to keep in mind. First, since stock prices are constantly changing, so are P/E ratios. It isn't unusual for a stock's P/E ratio to vary significantly within a relatively short period of time. P/E ratios also change quarterly as new earnings data is released.

Second, there are several different ways P/E can be calculated, depending on the one-year period you're using to determine the company's annual earnings. For example, by using a company's past four quarters of earnings, you can calculate the trailing 12 months, or TTM, P/E ratio. By using the company's expected earnings over the next four quarters, you can calculate its forward P/E ratio. There are other P/E calculation methods that can be useful as well, depending on the situation.

Why does the P/E ratio of companies vary so much?

Essentially, there are a few main factors that determines a company's P/E ratio. The first is the general market environment. For example, the stock market has risen by 81% over the past five years, and the average P/E of stocks has risen during this time as well. The same can be said for specific sectors -- if the market has a positive view of the tech sector, for example, it can cause tech P/E ratios to rise.

^SPX Chart

^SPX data by YCharts.

Next is financial strength and any company-specific risk. Companies that are perceived by investors as stronger or more stable tend to trade for higher P/E ratios when compared to similar companies that are thought to be riskier.

Finally and perhaps most influential is growth or, more specifically, the expectation of growth. Rapidly growing companies often trade at astronomical P/E ratios. The idea is that these stocks are trading based on their future earnings potential. Good examples of rapidly growing stocks with large P/E ratios are Amazon.com and Netflix, which trade for TTM P/E ratios of 253 and 244, respectively, as of this writing. On the other hand, Johnson & Johnson, which is considered to be a mature business, trades for a much lower P/E of 23.

The Foolish bottom line on P/E

P/E ratios are certainly useful when evaluating stocks, but are just one piece of the puzzle. Since P/E ratios vary tremendously among different companies, there are several other metrics to take into account when you're trying to determine whether a stock is cheap or expensive.

Just to name a few, the PEG ratio is extremely useful for growing companies, free cash flow is great for valuing companies whose earnings may be misleadingly low due to non-cash expenses, and the price-to-book, or P/B ratio can help you determine a stock's valuation compared with the value of its assets.