What is the basic structure of American higher education?
This flow chart, from the National Center for Education Statistics, summarizes it better than any explanation I can think of.

https://nces.ed.gov/programs/digest/d01/fig1.asp



Everywhere you see an arrow represents a potential change of institutions, or (above the black line) a natural place to exit formal education if desired.  In particular, most people who pursue graduate or professional study do so at a different institution than their undergraduate institution.  (They are usually eligible to apply for a graduate program at their undergraduate institution, if it's offered, but don't receive any special preference over applicants from other institutions.)

I'd also note that in many fields, one can go from an undergraduate program directly into a PhD program, without having to get a masters first.  In that case the PhD program normally takes more time (say about 5 years), and may or may not award a masters degree "en passant".