You can use this formula as well (courtesy of Park Tool's website):
L = 2 (C) + (F/4 + R/4 + 1)
L = Chain length in inches. Round the final result to closest whole inch figure.
C = Chain stay length in inches, measure to closest 1/8”, convert to decimal.
F= Number of teeth on largest front chainring.
R= Number of teeth on largest rear cog.