How hard is it to change a (sub-)field right after starting a CS PhD?
If this is for the US, then there is plenty of time after acceptance to a doctoral program to choose a specialty, assuming you start with just a BS/BA degree. The early couple of years are course rich to get you prepared for qualifying exams. This gives you a chance to see advanced material in a number of specialties and also get acquainted with several faculty members.
If you take advantage of that, and establish a few relationships, then, by the time comps/quals roll around you will be in a good position to choose some narrow specialty and work with an advisor to find a suitable problem.
Other places the system and expectations might be quite different, but if you are now an undergraduate it is probably too early to choose. I studied mathematics and started grad school with an interest in both Analysis and Topology. I might have jumped either way, but wound up in Analysis. But both of those are still pretty broad. Both have several subfields.
An advantage of choosing (rather) late is that you get a chance to evaluate the faculty for their likely support for your studies. I started with a poor advisor, but finished with a really great one.