It's a push that even the United Federation of Planets has a trillion beings, never mind Starfleet itself. According to Picard in First Contact, the Federation has "over 150" members. Assuming this is somewhere between 150 and 160, so say 155ish (or else why not say "over 160", "over 170", etc), and assuming an average population of 5 billion per planet, we have a total population for the Federation of something like 775 billion sentient beings. The Star Trek Star Charts book gives a more optimistic population figure of 985 billion, but that also seems to include "affiliates" as well as 183 full members.
We should also consider that Starfleet Headquarters doesn't have to be entirely contained in San Francisco. That could just be the "executive office space". There's Spacedock in Earth orbit, which can comfortably hold something like ten million people assuming the same population density as a Constitution-class starship. Are there multiple Spacedocks? We also know that Starfleet Academy specifically has "satellite campuses" on over 80 planets as of 2401, so it's not entirely located in San Francisco or even on Earth.