Tanh Calculator
Compute the hyperbolic tangent activation function output for a given input.
About Tanh Calculator
Tanh squashes real-valued inputs into the range (−1, 1): tanh(x) = (e^x − e^(−x)) / (e^x + e^(−x)), and is simply a rescaled and shifted version of the sigmoid function (tanh(x) = 2·σ(2x) − 1). Its key advantage over sigmoid is being zero-centered, meaning outputs can be negative, which helps keep gradients balanced during training. Like sigmoid, its derivative, 1 − tanh(x)², is at most 1 (at x=0) and shrinks toward 0 for large |x|, so tanh still suffers from vanishing gradients in very deep networks, but it remains a standard choice for RNN/LSTM hidden state activations.
Formulas
Tanh function
tanh(x) = (e^x - e^(-x)) / (e^x + e^(-x))
- x
- Input value
- e
- Euler's number (≈2.718)
Tanh derivative
tanh'(x) = 1 - tanh(x)^2
- tanh(x)
- Tanh output at x
Worked example
With the default values below, Tanh Calculator returns tanh(x) of 0.761594. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Input (x)accepts -100–100
- 1
Results
- tanh(x)
- 0.761594
- tanh'(x)
- 0.419974
Step by step
- 1tanh(x) = (e^x − e^(−x)) / (e^x + e^(−x))= 0.761594
- 2Derivative: 1 − tanh(x)²= 0.419974
Assumptions and limits
- The result is derived only from the single input listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 6 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
How is tanh related to sigmoid?
Tanh is a rescaled sigmoid: tanh(x) = 2σ(2x) − 1, which maps sigmoid's (0,1) output range to (−1,1) — both share the same S-shaped curve, but tanh's zero-centering often makes it converge faster in practice for hidden layers.
Why is being zero-centered an advantage?
When an activation function's outputs are all positive (like sigmoid's), gradients for the next layer's weights tend to all move in the same direction, slowing convergence; tanh's symmetric (−1,1) output allows both positive and negative signals, generally leading to more balanced gradient updates.
Where is tanh commonly used in modern architectures?
Tanh remains standard for the hidden state and gate activations inside LSTM and GRU recurrent cells, and appears in the GELU approximation formula, though it has largely been replaced by ReLU-family functions in standard feedforward and convolutional hidden layers.
