IM and Peds both have the largest scope of subspecialties.
Surgery also has quite a number (vascular, colorectal, cardiothoracic, surgical oncology, plastics, etc.)
So they're flexible in that if you're undecided on what you want to do, there are a lot of paths to take. I think most people have a good idea of what subspecialty they'll pursue by the time they choose a residency.
Pretty much every specialty has various subspecialties within it, but not as many as IM or Peds or Surg. Emergency Medicine has toxicology. ENT has neuro-otology. Anesthesia has pain and critical care. And the list goes on and on.
If you want career/time/practice flexibility, that's a whole 'nother story.