A stock represents partial ownership of a corporation. When you buy shares of a stock, you effectively own a small fraction of that company. Stocks of public companies are traded on stock exchanges like the NYSE or the NASDAQ.
Owning a stock entitles you to share in the future profits of the company. The value of a company is essentially the value of its future cash flows. So the value of a stock is the value of a fraction of the future cash flows of the company.
Some companies pay out part of their profits through dividends. You can also benefit from a price increase of the company stock.
Buying stocks is a risky investment, as neither dividends not price increases are certain and the stock can even lose part or all of its value.