NDCG Calculator (Normalized Discounted Cumulative Gain)
Paste a ranked list of relevance scores and get NDCG@k, plus the DCG, IDCG, ideal ordering and every position's gain and log discount. Linear or exponential gain, matches scikit-learn's ndcg_score. No signup, nothing uploaded.
How it works
NDCG (Normalized Discounted Cumulative Gain)measures how good a ranked list is, rewarding relevant results placed near the top. It is the headline quality metric for search ranking, recommender systems and learning-to-rank models. The definition here follows Järvelin & Kekäläinen (2002) and the implementation in scikit-learn's ndcg_score.
Positions are 1-indexed. For a predicted ranking with relevance scores rel₁ … relₙ and cutoff k, the score is built in four steps:
- Gain. Turn each relevance into a gain. Linear gain is
gᵢ = relᵢ; exponential gain isgᵢ = 2^relᵢ − 1(Burges et al., 2005), which rewards highly relevant hits more. - Discount. Divide each gain by a position discount
dᵢ = log2(i + 1), so rank 1 has discount log2(2) = 1 and lower ranks are penalised more. - DCG@k. Add the discounted gains over the top k:
DCG@k = Σᵢ₌₁..ₖ gᵢ / log2(i+1). - Normalise. Compute
IDCG@k— the DCG of the ideal ranking, the same relevances sorted from best to worst — thenNDCG@k = DCG@k / IDCG@k, a value in [0, 1].
When IDCG@k is 0 — every relevance is 0 — NDCG is undefined because it would divide by zero. The tool reports 0 and flags it, the same convention scikit-learn uses. If you set k larger than the number of items, it is clamped to the list length with a notice. As a credibility check, the calculator computes NDCG a second way — the gain·discount vector form scikit-learn uses internally — and confirms the two routes agree to floating-point precision. This version scores one ranking and derives the ideal order by sorting the relevances you enter; mean NDCG across many queries is a separate calculation.
Worked examples
Frequently asked questions
Sources & references
- Järvelin & Kekäläinen (2002), Cumulated gain-based evaluation of IR techniques, ACM TOIS 20(4) — the canonical DCG and normalized form
- scikit-learn — sklearn.metrics.ndcg_score: the log2(i+1) discount and linear vs exponential gain options this tool matches
- Burges et al. (2005), Learning to Rank using Gradient Descent, ICML — origin of the 2^rel − 1 exponential gain
- Wikipedia — Discounted cumulative gain: cross-check of both gain conventions and the IDCG normalization
The formulas on this page were last cross-checked against these sources on 2026-06-10. NDCG is a stable mathematical definition, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled against scikit-learn.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.