In most cases, you don’t have to pay to get a Ph.D. in CS. Instead, the university will pay you to get a Ph.D.! This might seem to good to be true, but it is true, and it is how the vast majority of CS/CE students pay for their Ph.D.
How can that be?
The key is that Ph.D. students are both students and employees of the university. In most cases, you will have either a research assistantship (RA) or a teaching assistantship (TA). With GSR you are paid to perform research. With a TA, you are paid to help a professor teach a course. In both cases, the assistantship includes your tuition and a stipend to cover your living expenses.
In 2019, The Taulbee Survey (Tables G1 and D5) reported that 84% of Ph.D. students received one of these forms of support. Of those, 34% had TAs, 58% had RAs, and 8% of students were on fellowship.
The size of the stipend depends on many factors, but in most cases it will allow you to live modestly during grad school without incurring additional debt. According to the Taulbee Survey (Table G2), median TA stipends ranged from $19,000-$26,000 per year in 2019. Research assistantships range from $20,000-$24,000. They vary depending on the local cost of living and other factors.
There are also fellowships available for various sources that will also cover your tuition and stipend.
When you are admitted to a Ph.D. program, they will provide details about the RA/TA they will provide. The Taulbee Survey can be useful in seeing how that offers compares to other peer institutions.
Where does the money come from?
For GSRs, the money comes from research grants and contracts. In the US and Canada, most CS research is funded by the government agencies (e.g., the National Science Foundation (NSF) in the US) through grants or by companies through research contracts.
In either case, a professor writes a proposal for funding to work on a project. Most of the resulting money goes to pay graduate researchers (i.e., Ph.D. students) to do much of the coding, writing, experimentation, and thinking that goes into doing research. Usualy, that work will correspond directly to the research that will, eventually, become your Ph.D. thesis.
For TAs, the money comes from the university to help support their teaching mission.
So, I don’t need more loans?
The short answer is “No”.
The longer answer is that, of course, it depends on your financial situation. However, most students do not acrue more student debt to get a Ph.D.
Not only that, you can often defer your existing student loans because you will still be a student (You should check the terms of your particular loans, obviously).
Are there other sources of income as a Ph.D. student?
Many students do internships during the summer, and they can let you save a chunk of money during the summer to supplement your GSR during the school year.
Working a second job as a Ph.D. student during the school year is less common. Being a Ph.D. student is really a full-time job.