Connect via MCP →

Enter Calculation

Formula

Show calculation steps (2)
  1. First Derivative

    First Derivative: tanh(x) Hyperbolic Tangent Function Calculator

    first derivative of tanh at x equals 1 minus tanh squared

  2. Second Derivative

    Second Derivative: tanh(x) Hyperbolic Tangent Function Calculator

    second derivative of tanh at x

Advertisement

Results

tanh(x)
0.4621171573
dimensionless, range (-1, 1)
First derivative f'(x) = 1 - tanh(x)^2 0.786447733
Second derivative f''(x) = -2 tanh(x) (1 - tanh(x)^2) -0.7268619814

What is the tanh function?

The hyperbolic tangent, written \(\tanh(x)\), is a smooth S-shaped (sigmoidal) function defined for every real number x. It is defined as the ratio of the difference and sum of the exponentials \(e^x\) and \(e^{-x}\). Its output always lies strictly between -1 and 1, and it is an odd function, meaning \(\tanh(-x) = -\tanh(x)\). In machine learning, tanh is a popular neuron activation function because it is zero-centered, which often helps gradient-based training converge faster than a 0-to-1 sigmoid.

S-shaped tanh curve on x-y axes bounded between -1 and +1
The tanh function is an S-shaped curve that maps any real input into the range (-1, 1).

How to use this calculator

Enter any real number for x and the tool instantly returns \(\tanh(x)\) together with two optional derivatives that are useful in calculus, physics, and back-propagation. Negative numbers, decimals, and very large magnitudes are all accepted. For large positive x the value saturates toward +1; for large negative x it saturates toward -1.

The formula explained

The core definition is $$\tanh(x) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}$$ The denominator is always at least 2, so there is never a division-by-zero. The first derivative follows the elegant identity $$f'(x) = 1 - \tanh^{2}(x),$$ also written \(\operatorname{sech}^{2}(x)\). Differentiating again gives the second derivative $$f''(x) = -2\,\tanh(x)\left(1 - \tanh^{2}(x)\right).$$ For numerical stability with very large |x|, an exponential-of-(-2x) reformulation is used internally to avoid overflow.

Advertisement
Diagram showing exponential growth and decay curves combining into tanh
tanh(x) is built from the exponentials \(e^x\) and \(e^{-x}\).

Worked example (x = 0.5)

Using \(e^{0.5} = 1.6487212707\) and \(e^{-0.5} = 0.6065306597\), $$\tanh(0.5) = \frac{1.0421906110}{2.2552519304} = 0.4621171573.$$ The first derivative is $$1 - 0.4621171573^{2} = 0.7864477623,$$ and the second derivative is $$-2 \times 0.4621171573 \times 0.7864477623 = -0.7269989018.$$

FAQ

What is the range of tanh? The open interval (-1, 1); it approaches but never reaches the endpoints.

What is tanh(0)? Exactly 0, with \(f'(0) = 1\) and \(f''(0) = 0\).

Why use tanh instead of sigmoid? tanh is zero-centered (outputs are symmetric about 0), which can speed up neural-network learning, while a logistic sigmoid outputs only positive values between 0 and 1.

Last updated: