How do you size an expansion tank. I will be replacing all piping & gas heater. I see 2 gallons & 5 gallons at the store...

I will be placing a 40 or 50 gal. gas water heater.

Thanks