Everything starts from occupant load, calculated from area and the occupancy load factor (IBC Table 1004.5). The fixture count is driven by people, so an error here propagates into the fixture count.
Fixtures are generally calculated separately for each sex. The code commonly directs a 50/50 split of the occupant load unless the nature of the occupancy indicates a different distribution. Apply the split before the ratio.
Go to IBC Table 2902.1 / IPC Table 403.1 and find your occupancy classification (Business, Mercantile, Assembly, Restaurant/food service, Educational, etc.). Each lists ratios such as "one water closet per N persons" and "one lavatory per N persons." These ratios differ by occupancy — a restaurant is not a business is not an assembly — and can change between code editions, so read them from the adopted edition.
Fixture math almost never comes out even. The code requires rounding up to the next whole fixture — you can't provide a fraction of a water closet.
Beyond WCs and lavatories, the table requires a number of drinking fountains (by occupant load) and at least one service sink (mop sink) for most occupancies. Don't forget these — their omission is a common comment.
For restroom layout and sex-separation rules, see our commercial restroom guide.
Method per the model IBC/IPC; the exact ratios in your adopted edition's Table 2902.1 / 403.1, plus local amendments, govern. Verify against your codes of record.