While both are graduate degrees, each has a very different goal and scope. An Masters typically takes ~1-2 years to complete (full time) and focuses primarily on coursework. Some Masters degrees involve a thesis component, and the thesis may be research, but typically the research expectations are modest, often replicating some existing discovery or making a more incremental advance. MS degrees can be great ways to learn advanced topics in CS; and some have a particular professional focus, such as software engineering, design, or other topics that can prepare you for careers beyond software engineering, such as interaction design, product management, or engineering management. In most cases, you pay tuition for an MS degree.
A doctoral degree, in contrast, can take 5-6 years to complete (after a BS or BA) and focuses primarily on providing training in how to do research. Courses are only a small fraction of a PhD program; most of your time is spent answering questions that no one in the world has answered yet. PhD is excellent preparation for research and teaching-related careers in academia, industry, and government labs, as well as for positions that involve translating basic research discoveries into practice. In most cases, you are paid to do a PhD, working as a research assistant or teaching assistant, or earning a fellowship that frees you to pursue research.