Connect via MCP →

Enter Calculation

Formula

Show calculation steps (2)
  1. First Derivative

    First Derivative: Hyperbolic Tangent tanh(x) Function and Derivatives Calculator

    First derivative of tanh(x), where t = tanh(x)

  2. Second Derivative

    Second Derivative: Hyperbolic Tangent tanh(x) Function and Derivatives Calculator

    Second derivative of tanh(x), with t = tanh(x)

Advertisement

Results

tanh(x)
0
dimensionless
First derivative tanh'(x) 1
Second derivative tanh''(x) -0
x tanh(x) tanh'(x) tanh''(x)
-5 -0.99991 0.00018 0.00036
-4.5 -0.99975 0.00049 0.00099
-4 -0.99933 0.00134 0.00268
-3.5 -0.99818 0.00364 0.00727
-3 -0.99505 0.00987 0.01963
-2.5 -0.98661 0.02659 0.05247
-2 -0.96403 0.07065 0.13622
-1.5 -0.90515 0.18071 0.32713
-1 -0.76159 0.41997 0.6397
-0.5 -0.46212 0.78645 0.72686
0 0 1 -0
0.5 0.46212 0.78645 -0.72686
1 0.76159 0.41997 -0.6397
1.5 0.90515 0.18071 -0.32713
2 0.96403 0.07065 -0.13622
2.5 0.98661 0.02659 -0.05247
3 0.99505 0.00987 -0.01963
3.5 0.99818 0.00364 -0.00727
4 0.99933 0.00134 -0.00268
4.5 0.99975 0.00049 -0.00099
5 0.99991 0.00018 -0.00036

What is the hyperbolic tangent?

The hyperbolic tangent, written \(\tanh(x)\), is one of the basic hyperbolic functions. It is defined as the ratio of the hyperbolic sine to the hyperbolic cosine, \(\tanh(x) = \sinh(x)/\cosh(x)\). For real inputs its output is always strictly between -1 and 1, and the function passes smoothly through the origin. Because it is smooth, bounded and S-shaped, tanh is widely used as an activation function in neural networks and as a soft saturation curve in signal processing.

S-shaped tanh curve crossing the origin and approaching horizontal asymptotes at +1 and -1
The tanh(x) function rises smoothly through the origin and approaches +1 and -1 as x grows large.

How to use this calculator

Enter a value of x to instantly read \(\tanh(x)\), its first derivative \(\tanh'(x)\), and its second derivative \(\tanh''(x)\). To explore the shape of the curves, fill in the range fields: a start value, an end value, and a positive step size. The calculator then builds a table of \(x\), \(\tanh(x)\), \(\tanh'(x)\) and \(\tanh''(x)\) across the range. The step must be greater than zero and the end must be at least the start, otherwise the table is skipped.

The formulas explained

The function is $$\tanh(x) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}.$$ Its derivative has the elegant form $$\tanh'(x) = 1 - \tanh^{2}(x) = \operatorname{sech}^{2}(x),$$ which is always positive and peaks at 1 when \(x = 0\). Differentiating once more gives $$\tanh''(x) = -2\,\tanh(x)\left(1 - \tanh^{2}(x)\right).$$ For numerical stability with large \(|x|\) we use the standard library tanh, which avoids exponential overflow.

Advertisement
Three overlaid curves showing tanh and its first and second derivatives
tanh(x) shown with its first derivative (bell-shaped) and second derivative.

Worked example

Take \(x = 1\). Then \(e^{1} = 2.718281828\) and \(e^{-1} = 0.367879441\), so $$\tanh(1) = \frac{2.718281828 - 0.367879441}{2.718281828 + 0.367879441} = 0.761594156.$$ The first derivative is $$1 - 0.761594156^{2} = 0.419974341,$$ and the second derivative is $$-2 \times 0.761594156 \times 0.419974341 = -0.639700.$$

FAQ

What is tanh(0)? \(\tanh(0) = 0\), \(\tanh'(0) = 1\) (the steepest slope), and \(\tanh''(0) = 0\).

Is tanh odd or even? tanh is an odd function, \(\tanh(-x) = -\tanh(x)\). Its first derivative is even and its second derivative is odd.

What is the range of tanh? The output approaches -1 as x goes to negative infinity and 1 as x goes to positive infinity, but never reaches them, so the range is the open interval \((-1, 1)\).

Last updated: