Value investing pioneer Benjamin Graham once said that in the short run, the stock market is a voting machine, but, in the long run, it is a weighing machine.

Once a company goes public on the stock market and its shares start trading on an exchange, the share price is determined by supply and demand. But, over the long term, share prices are determined by the economics of the business. It's impossible to predict exactly what a stock will do and when, but we can study how share price movement works. Let's unpack Graham's statement a little more and go over how stock prices work.

A woman tracking stock prices on a computer screen.
Image source: Getty Images.

How do stock prices work?

It starts with the initial public offering (IPO). Companies work with investment bankers to set a primary market price when a company goes public. That price is set based on valuation and demand from institutional investors.

After that initial offering, the stock starts to trade on secondary markets -- that is, stock exchanges such as the New York Stock Exchange (NYSE) or the Nasdaq. This is where we get into the market being a voting machine.

For highly traded stocks, there are buyers and sellers on each side constantly bidding and asking for new prices. Institutions trying to build huge positions and even brokerages working for individual investors will bid for stocks. If there are more buyers than sellers, the price will get bid up. If there are more sellers than buyers, the opposite will happen.

That's why Graham called the market a voting machine. On a second-by-second basis, the price of the stock reflects what current buyers are willing to pay and what current sellers are willing to take. This may sound familiar if you took economics in college. It's the same principle for any commodity: The price is determined by supply and demand.

Understanding what determines stock price

Now let's get to the weighing machine part. Over the long term, stock prices are determined by the earnings power of the business. Remember, a stock is a share of an actual business. The better the business does, the better the stock will do.

Graham's protege, billionaire investor Warren Buffett, says that a stock is worth the discounted value of the stream of cash flows it will earn over the life of the business. To get the valuation of the business, he will estimate the amount of earnings the business will make in the future and then discount the future years because money now is worth more than money you could get later on.

Often a stock will deviate from that valuation, however. If it trades for less than the value, it is considered undervalued. If it trades for more, it is considered overvalued. Eventually, the stock price reverts to the value as the market weighs the stock price based on the earning power of the business. Investors who look to take advantage of those deviations by buying undervalued stocks and shorting overvalued stocks are called value investors

How market cap affects price

The market cap of a stock is equal to the total shares times the share price. It's the price it would take to buy all of a company's outstanding shares. Many stocks issue more shares to fund the business, so it is important to base valuation on the market cap and not just the stock price. The more shares that are issued, the less of a fraction of the business you own.

On the other side, if a business buys back shares, the price of each one of your shares will need to go up to maintain the same market cap. Share buybacks are generally cheered by shareholders as long as the stock price isn't overvalued.

Example of a share price valuation

We don't have the space here to do a full-blown discounted cash flow analysis as Buffet would like, but we can use a shortcut. The price-earnings ratio (P/E) shows the price of the stock relative to earnings. It's calculated by dividing the stock price by earnings per share. Earnings per share is a readily available number on most financial websites and the company's quarterly reporting documents.

Let's look at Home Depot (NYSE:HD) as an example. As of September 2021, Home Depot is $330.34 per share, and its earnings per share over the past 12 months are $14.20. That's a P/E of 23.27.

That number doesn't mean much by itself, so we need to compare it to its historical numbers. Over the past five years, Home Depot has averaged a P/E of 22.96, which is right in line with the current price. If that P/E had been substantially higher than the current one, Home Depot probably would have been a strong stock investment. Value investors tend to look for stocks with lower P/E ratios.

Related investing topics

Conclusion

In the short term, the price of a stock is vulnerable to the emotional whims of the crowd. But, in the long term, smart investors can pinpoint where the emotions of the crowd set up opportunity. Focus on the long term in your investing, and don't let other people's emotions affect your investment decisions.

Mike Price has positions in Home Depot. The Motley Fool has positions in and recommends Home Depot. The Motley Fool has a disclosure policy.