The minimum size of the WH vent pipe is 3” (assuming that this is the size of the WH draft hood and that there’s no other appliances connected to the same flue) and the flue diameter depends on its developed height (starting from the draft hood, all the way to the top of the chimney).
To find out the flue size you need to know BTU’s of your appliance (usually listed on the WH tag), chimney’s height and type (double wall metal, masonry, etc), lateral of the connector (horizontal / pitched section between the WH and the chimney’s vertical part).
Natural Draft water heater’s rating – 40 000 BTU
Distance (lateral) between the WH’s draft hood and vertical chimney connection – 5’
Chimney’s height – 20’
Using the above numbers and tables at the link provided the flue diameter would be:
TABLE 504.2(4) MASONRY CHIMNEY
When you pick 20 from the first column, 5 from second, 3” diameter would be too small because it only allows up to 35K BTU’s (column marked NAT under 3” diameter) so you need 4” (up to 67K BTU’s)
The same calculations for a metal, double wall chimney using TABLE 504.2(1) TYPE B DOUBLE-WALL GAS VENT show that you can use 3” diameter flue.
However, it is also possible that you local jurisdiction requires 4” flue as a minimum even if the table allows smaller size.
Let me know if you have more questions, just click “comment” under this answer.