The main difference between speculating and investing is the amount of of risk undertaken in the trade. Typically, high-risk trades that are almost akin to gambling fall under the umbrella of speculation, whereas lower-risk investments based on fundamentals and analysis fall into the category of investing.
Investors seek to generate a satisfactory return on their capital by taking on an average or below-average amount of risk. On the other hand, speculators are seeking to make abnormally high returns from bets that can go one way or the other. It should be noted that speculation is not exactly like gambling because speculators do try to make an educated decision on the direction of the trade, but the risk inherent in the trade tends to be significantly above average.
As an example of a speculative trade, consider a volatile junior gold mining company that has an equal chance over the near term of skyrocketing from a new gold mine discovery or going bankrupt. With no news from the company, investors would tend to shy away from such a risky trade, but some speculators may believe that the junior gold mining company is going to strike gold and may buy its stock on a hunch. This would be speculation.
As an example of investing, consider a large stable multinational company. The company may pay a consistent dividend that increases annually, and its business risk is low. An investor may choose to invest in this company over the long-term to make a satisfactory return on his or her capital while taking on relatively low risk. Additionally, the investor may add several similar companies across different industries to his or her portfolio to diversify and further lower their risk.