Skip to content
Calcrivo

Binary Cross-Entropy Calculator

Calculate binary cross-entropy loss from a true label and predicted probability.

Inputs

Model's predicted probability that y = 1.

Binary Cross-Entropy Loss

0.223144

Positive-Class Term

-0.223144

Negative-Class Term

-0.000000

Step by step

  1. Positive-class term: y × ln(p)

    1 × ln(0.8000)

    = -0.223144

  2. Negative-class term: (1 − y) × ln(1 − p)

    (1 − 1) × ln(1 − 0.8000)

    = 0.000000

  3. BCE: −(positive term + negative term)

    −(-0.223144 + 0.000000)

    = 0.223144

How it works

Binary cross-entropy measures how far a predicted probability is from the true binary label: BCE = −(y·ln(p) + (1−y)·ln(1−p)). When y = 1, only the first term is active and loss grows as p moves away from 1; when y = 0, only the second term is active and loss grows as p moves away from 0. This is the standard loss function for binary classifiers with a sigmoid output, and it penalizes confident wrong predictions far more heavily than a squared-error loss would, since ln(p) → −∞ as p → 0.

Formula

BCE = -(y × ln(p) + (1 - y) × ln(1 - p))

y
True binary label (0 or 1)
p
Predicted probability that y = 1

Frequently Asked Questions

Why does BCE use natural log instead of log base 2?

Natural log (ln) is the conventional choice in most deep learning frameworks because it simplifies the gradient during backpropagation through the sigmoid function; log base 2 would just scale the loss by a constant factor (1/ln(2)) without changing which model is 'better.'

What happens if p is exactly 0 or 1 and the prediction is wrong?

The loss becomes infinite in theory (ln(0) is undefined/−∞), which is why in practice predicted probabilities are clamped to a small epsilon away from exactly 0 or 1 before computing the loss, as this calculator does internally.

How is BCE related to log loss?

They are the same formula — 'log loss' is simply the more general/statistical name for binary cross-entropy loss applied to a single sample; averaging BCE over many samples gives the dataset-level log loss reported by tools like scikit-learn.

You might also need