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

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 graphic showing the factors that affect stock price: company health, supply, economic reports, demand and trader sentiment.
Image source: The Motley Fool.

How do stock prices work?

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. The price is set based on valuation and demand from institutional investors.

After the 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 might sound familiar if you took economics in college. It's the same principle for any commodity: The price is determined by supply and demand.

Law of Supply and Demand

The law of supply and demand is an economic theory asserting that supply and demand will meet each other at a certain equilibrium price.

Understanding what determines stock price

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 deviations by buying undervalued stocks and shorting overvalued stocks are called value investors

How market cap affects price

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.

How to tell if a stock is "cheap"

How to tell if a stock is "cheap"

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 (HD -0.74%) as an example. As of May 2023, Home Depot was trading at $291 per share, and its earnings per share over the past 12 months were $16.68. That's a P/E of 17.44.

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 above the current valuation. Because the P/E average had been higher than the May ratio, Home Depot could be an attractive stock investment. Value investors tend to look for stocks with lower P/E ratios.

Bid and Ask

Bid and ask are two points of a price quote. Bid is the price investors will pay for an asset, while ask is the price they’ll sell it for.

Related investing topics

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.

Lou Whiteman has positions in Home Depot. The Motley Fool has positions in and recommends Home Depot. The Motley Fool has a disclosure policy.