Tanh Activation Function Calculator

Tanh Function

tanh(x) = (ex - e-x) / (ex + e-x)
0.000000
Range: (-1, 1)
1.000000
tanh'(x) = 1 - tanh²(x)

Visualization

Formulas

Tanh Function
f(x) = (e^x - e^(-x)) / (e^x + e^(-x))
Derivative
f'(x) = 1 - tanh(x)^2
Alternative: tanh(x) = 2 * sigmoid(2x) - 1

Properties

  • • Output range: (-1, 1)
  • • Zero-centered output
  • • Stronger gradients than sigmoid
  • • Maximum derivative at x=0 (1.0)

Tanh vs Sigmoid

PropertyTanhSigmoid
Range(-1, 1)(0, 1)
Zero-centeredYesNo
Max derivative1.00.25

What is the tanh activation function?

The hyperbolic tangent (tanh) function is defined as tanh(x) = (e^x − e^(−x)) / (e^x + e^(−x)), mapping inputs to the range (−1, 1). It is a rescaled version of the sigmoid function: tanh(x) = 2σ(2x) − 1. Tanh is preferred over sigmoid in hidden layers because it is zero-centered, meaning its outputs have a mean closer to zero, which helps gradients flow more effectively during backpropagation. The derivative is tanh'(x) = 1 − tanh²(x), with a maximum of 1.0 at x = 0. Tanh is commonly used in recurrent neural networks (RNNs), LSTM cell state updates, and as the activation in hidden layers of shallow networks. Like sigmoid, it suffers from vanishing gradients for large input magnitudes, which is why ReLU has replaced it in most deep architectures.

Built with care by Alpiaal