NDCG Calculator

Compute DCG, IDCG and NDCG@k from the relevance grades of a ranked result list, with linear or exponential gain.

Paste a full judged set so the ideal ranking includes relevant documents your system missed.

Last updatedHow we build & check our tools
Results will appear here once you enter your values.

How NDCG is calculated

Discounted cumulative gain. Each result at position i earns a gain from its relevance grade, and that gain is divided by log2(i + 1). Position 1 keeps its full gain (discount 1.0), position 2 keeps 63.1%, position 3 keeps 50%, and position 10 keeps only 28.9%. Summing the discounted gains down to the cutoff k gives DCG@k.

Normalization. DCG on its own depends on how many relevant documents a query has, so it cannot be averaged across queries. NDCG divides DCG@k by IDCG@k, the DCG of the best possible ordering of the judged grades. The result lies between 0 and 1, where 1 means no reordering could improve the top k.

Worked example. For grades 3, 2, 3, 0, 1, 2 with linear gain, DCG@6 = 3 + 1.262 + 1.5 + 0 + 0.387 + 0.712 = 6.861. Sorting those same six grades gives 3, 3, 2, 2, 1, 0 and IDCG@6 = 7.141, so NDCG@6 = 0.9608, which matches scikit-learn ndcg_score.

Linear or exponential gain

Linear gain uses the grade itself, rel. It follows the original cumulated gain measures of Jarvelin and Kekalainen (2002) and is what scikit-learn dcg_score and ndcg_score compute. A grade 3 document is worth exactly three times a grade 1 document.

Exponential gain uses 2^rel - 1, popularized by Burges et al. (2005) for learning to rank and common in web search and Kaggle competitions. Grade 3 is worth 7 and grade 1 is worth 1, so putting a highly relevant document on top matters far more. On the example list above, exponential DCG@6 rises to 13.848.

Pick one and keep it. The two variants give identical results for binary relevance (0 or 1), but with graded labels they produce different numbers and can even rank two systems differently. Always report which gain you used alongside the NDCG value.

Common NDCG mistakes

Building IDCG from retrieved results only. If the ideal list is just your own results sorted, a system that misses the best documents entirely can still score 1.0. The Wikipedia example shows the gap: with two more judged documents of grade 3 and 2 that were never retrieved, the ideal top six becomes 3, 3, 3, 2, 2, 2, IDCG@6 rises to 8.740, and NDCG@6 drops from 0.961 to 0.785. Paste the full judged set when you have it.

Queries with no relevant documents. When every judged grade is 0, IDCG is 0 and NDCG is a division by zero. This calculator shows n/a. Evaluation libraries differ here: some skip those queries and some score them as 0, which changes the mean.

Tied scores. This tool takes an explicit ranking. scikit-learn instead ranks by predicted scores and, by default, averages the gain over tied scores, so its result can differ when your model outputs ties.

Reading NDCG at different cutoffs

Choose k to match the interface. NDCG@1 only asks whether the top result is as relevant as the best available one. NDCG@3 or @5 fits a chat assistant or RAG pipeline that passes a handful of chunks to a model, and NDCG@10 mirrors a first page of search results and is the main metric on the BEIR retrieval benchmark.

Watch the curve, not one number. On the example ranking, NDCG@1 is 1.0, NDCG@3 is 0.978 and NDCG@5 is 0.861. The drop between 3 and 5 comes from the grade 0 document at position 4 pushing a grade 2 document down. The per-position table shows exactly which slot costs the most discounted gain.

When k exceeds the list. If fewer than k results were returned, both DCG and IDCG are cut at the list length here, the same as scikit-learn with a single list of scores.

Frequently Asked Questions

Common questions about the NDCG Calculator

It depends on the dataset, the relevance scale and the cutoff, so compare systems on the same queries and judgments rather than against a fixed threshold. Scores from different benchmarks are not directly comparable. A score of 1.0 means the top k could not be reordered to gain more, while scores near 0 mean relevant documents sit very low in the ranking or were not retrieved at all.
From the same team

Stop paying per token — route AI requests to your own GPU

Wide Area AI is a local-first AI gateway: repeated requests hit an edge cache, the rest run free on your own hardware, and the cloud is only a failover. OpenAI-compatible endpoint, free tier.

Start routing — free

Sources & References

Discounted cumulative gain

Worked example: relevance 3,2,3,0,1,2 gives DCG6 = 6.861, ideal 3,3,3,2,2,2 gives IDCG6 = 8.740 and nDCG6 = 0.785; describes the 2^rel - 1 variant.

sklearn.metrics.ndcg_score

Reference implementation with linear gain, the k parameter, tie averaging behavior and the Jarvelin and Kekalainen citation.

sklearn.metrics.dcg_score

Definition of unnormalized DCG with a log2 discount, used to generate the unit test reference values.

Explore More Tools

Explore these related tools for your next step.

ai

AI Energy & Water per Query Calculator

Estimate the electricity, water and CO2e behind your AI prompts, images and video seconds using published figures from Google, OpenAI, Epoch AI, the IEA and peer-reviewed studies. Switch between low, median and high estimates and set your own grid intensity and water use effectiveness.

Try it now
ai

Expected Calibration Error (ECE) Calculator

Paste predicted probabilities and 0/1 labels to get ECE, MCE, Brier score and log loss, a per-bin table and a reliability diagram. Binning matches scikit-learn calibration_curve with uniform or quantile bins.

Try it now
ai

Speculative Decoding Speedup Calculator

Estimate the walltime speedup from speculative decoding using the acceptance rate, draft length and draft model cost. Uses Theorem 3.8 from Leviathan, Kalman and Matias (2023) and finds the best number of draft tokens.

Try it now
ai

Text-to-Speech Cost Calculator

Compare ElevenLabs, OpenAI, Google Cloud, Amazon Polly and Azure text-to-speech costs for your script or monthly character volume. See the cheapest voice tier, cost per audio hour and which ElevenLabs plan covers your usage.

Try it now
ai

Precision-Recall Curve & Average Precision Calculator

Paste model scores and 0/1 labels to get the precision-recall curve, Average Precision exactly as scikit-learn computes it, trapezoidal PR AUC, the prevalence baseline and the best-F1 threshold.

Try it now
ai

AI Video Prompt Builder (Sora, Veo, Runway)

Describe a shot once (subject and action, camera move, lens, pace, dialogue and sound) and get a prompt formatted for Veo 3, Sora 2, Runway Gen-4 or any text-to-video model, ready to copy or download.

Try it now