Billions of shares of stock are bought and sold each day, and it's this buying and selling that sets stock prices. Stock prices go up and down when someone agrees to buy shares at a higher or lower price than the previous transaction. In the short term, this dynamic is dictated by supply and demand.

Here's a simple illustration: Imagine there are 1,000 people willing to buy one share of stock XYZ for $10, but there are only 500 people willing to sell one share of XYZ for $10. The first 500 buyers each snag a share for $10. The other 500 buyers who were left out then raise their offer price to $10.50. This higher offer price induces some owners of XYZ who didn't want to sell at $10 to agree to sell at $10.50. The stock price is now $10.50 instead of $10 since that was the price of the latest transaction.

A stock market screen displays real-time quotes.

Image source: Getty Images.

What can affect stock prices?

High demand for a stock relative to supply drives the stock price higher, but what causes that high demand in the first place?

Ultimately, demand for a stock is driven by how confident investors are about that stock's prospects. In the short term, things like quarterly earnings reports that beat expectations, analyst upgrades, and other positive business developments can lead investors to be willing to pay a higher price to acquire shares. On the flip side, disappointing earnings reports, analyst downgrades, and negative business developments can cause investors to lose interest, thus reducing demand and forcing sellers to accept lower prices.

In the long term, the value of a stock is ultimately tied to the profits generated by the underlying company. Investors who believe a company will be able to grow its earnings in the long run, or who believe a stock is undervalued, may be willing to pay a higher price for the stock today regardless of short-term developments. This creates a pool of demand undeterred by day-to-day news, which can push the stock price higher or prevent big declines.

Sometimes demand for stocks in general increases, or demand for stocks in a particular stock market sector increases. A broad-based demand increase can drive individual stocks higher without any company-specific news. One example: The COVID-19 pandemic led to consumers increasing spending online at the expense of brick-and-mortar stores. Some investors believe this change is here to stay, which led to an increase in demand and higher prices for e-commerce stocks across the board.

Another example: Falling interest rates reduce what savers and investors can earn from savings accounts and fixed-income investments like bonds. This can lead those looking for better returns to invest in other assets, like stocks or real estate, thus raising the demand for those assets and inflating prices.

The big picture is what matters

Long-term investors, like those of us at The Motley Fool, don't much care about the short-term developments that push stock prices up and down each trading day. When you have many years or even decades to let your money grow, things such as analyst upgrades and earnings beats are irrelevant. What matters is where a company will be five, 10, or 20 years from now.

While a lot of ink is spilled about daily fluctuations in stock prices, and while many people try to profit from those short-term moves, long-term investors should be laser-focused on a company's potential to increase its profits over many years. Ultimately, it's rising profits that push stock prices higher.