In many places, including the US, study for the doctorate, though perhaps not so much for the Master's. comes with some sort of funding. The funding is often dependent on work, either in a lab or as a TA (the most common case). In popular fields, such as math and CS, doctoral granting institutions also normally teach a lot of undergraduates. It is normally much more than what the full-time faculty can handle. I studied math long ago and there were two funded doctoral students for every faculty member. About 70 faculty and 140 TAs. We made dirt scratching wages, but it was enough, but only because our housing was also subsidized. I finished with a small family and a doctorate. My spouse was also a student in a different field with little funding.
But doctoral study isn't just tuition driven as undergraduate study is in much of the US.
Being a full time employee somewhere and also a full time doctoral candidate, however, is very difficult. If you have substantial financial obligations it is even more difficult unless you can find a part-time program (which exist).
However, if you can live on poverty level income for a while, you can earn a doctorate without substantial debt. It isn't the fastest way to a degree, of course, since you are a part-time employee, but it can be a good trade off. Note also that tuition isn't normally charged to TAs. However, US tax law is gettin weird. Some want to treat the tuition "grant" as taxable income, which becomes impossible to cover, given the low pay. Stupid. Stupid. Stupid. It is as if some people want a stupid citizenry. I'm not certain of the current state of that proposal.
If you intend to be a teaching scholar (as in the US) then a TA position will help you learn the art of teaching (by osmosis, mostly), so it contributes to the overall goal. But if you intend to be a research scholar, look for a funded lab that will get you deeper into the research a bit earlier.
I don't have personal experience in Europe, but from colleagues, I get the idea that doctoral students are more or less regular employees that do most of the things that regular faculty do, up to and including advising of other doctoral students. One friend successfully advised a doctorate for another student, but left without his own. These sorts of things seem to occur both in UK and in Germany, at least, but others there can give a more complete picture. The positions have a lot of responsibility, but you are low ranked and only adequately paid. But enough to raise a family at least, if that is an issue. Such positions of responsibility are uncommon in the US.
Caveat. My experience and the above is from Mathematics, computer science and some of the other "hard" sciences (what ever that means). It differs in other fields. See other answers here for very different situations: say indigochild. Someone has to be willing to pay for the support, government, foundations, industry, etc. Or the candidate as the last resort.