Inferensys

Glossary

Normalized Discounted Cumulative Gain (NDCG)

Normalized Discounted Cumulative Gain (NDCG) is a ranking quality metric that measures the usefulness of a ranked list, giving higher weight to relevant items appearing at the top positions and normalizing the score against an ideal ranking.
QA engineer performing AI quality assurance on laptop, test results visible, casual technical debugging session.
RANKING QUALITY METRIC

What is Normalized Discounted Cumulative Gain (NDCG)?

A measure of ranking quality that evaluates a list's usefulness by giving higher weight to relevant items at the top, then normalizing the score against an ideal ranking.

Normalized Discounted Cumulative Gain (NDCG) is a ranking quality metric that measures the usefulness of a ranked list by assigning higher weight to relevant items appearing at the top positions and normalizing the score against an ideal ranking. It extends Cumulative Gain (CG) by applying a logarithmic discount to penalize relevant items buried deep in the list, reflecting the diminishing user attention at lower ranks.

The metric is normalized by dividing the Discounted Cumulative Gain (DCG) of the predicted ranking by the DCG of the ideal ranking (IDCG), producing a score between 0 and 1. NDCG is the primary evaluation metric for learning-to-rank models and deep learning recommender systems, as it handles graded relevance judgments rather than binary labels, making it sensitive to the nuanced value of partially relevant items.

Ranking Quality Metric

Key Characteristics of NDCG

Normalized Discounted Cumulative Gain (NDCG) is the gold-standard metric for evaluating the quality of a ranked list. It measures not just relevance, but the positional importance of that relevance, normalizing the score against an ideal ordering to enable comparison across different queries.

01

Position-Aware Scoring

NDCG fundamentally operates on the principle that highly relevant items must appear at the top of a ranked list. Unlike flat metrics like precision, NDCG applies a logarithmic discount to relevance gains based on their position. An item at rank 1 contributes its full relevance score, while an item at rank 100 contributes a heavily discounted fraction. This directly models user behavior, where attention and click probability decay rapidly as users scan down a list of search results or product recommendations.

02

Multi-Graded Relevance

NDCG supports nuanced, non-binary relevance judgments. Instead of a simple relevant/irrelevant label, items are assigned a graded relevance score (e.g., 0 for 'irrelevant', 1 for 'tangential', 3 for 'relevant', 5 for 'perfect match'). This allows the metric to penalize a system that ranks a 'tangential' result above a 'perfect' one, even if both are technically 'relevant' in a binary sense. The gain is typically computed as 2^rel - 1, giving exponentially higher credit to higher relevance grades.

03

Ideal Normalization (IDCG)

The 'Normalized' in NDCG is its most critical feature. The raw Discounted Cumulative Gain (DCG) is divided by the Ideal DCG (IDCG)—the DCG of the perfect ranking for that specific query. This normalization bounds the score between 0.0 and 1.0, making it query-agnostic. A score of 1.0 indicates a perfect ranking. This allows you to average NDCG across a test set of diverse queries where the number of relevant items varies wildly, a scenario where raw DCG would be meaningless.

04

Calculation Formula

The formal definition is NDCG@k = DCG@k / IDCG@k. The DCG is calculated as the sum over all positions i up to k of (2^{rel_i} - 1) / log_2(i + 1). The numerator is the gain from the item's relevance grade, and the denominator is the positional discount. The IDCG is computed by sorting all items in the corpus by their true relevance grade in descending order and calculating the DCG of that ideal list. This normalization ensures the score reflects the system's ability to sort items correctly.

05

Cutoff Evaluation (NDCG@k)

NDCG is almost always evaluated at a specific cutoff k, denoted as NDCG@k (e.g., NDCG@10, NDCG@50). This focuses the evaluation on the top of the ranked list, which is the only part most users interact with. The choice of k is domain-specific: a search engine might optimize for NDCG@5, while a recommendation carousel might look at NDCG@20. This metric ignores the ordering of items beyond the cutoff, aligning the evaluation with the practical limits of a user interface.

06

Handling Missing Judgments

A practical challenge with NDCG is unjudged documents. In large-scale evaluation, it's impossible to label every item. The standard approach is to treat unjudged items as irrelevant (gain=0). This is a conservative assumption that penalizes systems for surfacing unvetted content. More advanced techniques like bpref or inferred relevance models exist, but the zero-gain assumption remains the industry default for its simplicity and safety, ensuring that systems are not rewarded for returning items of unknown quality.

METRIC COMPARISON

NDCG vs. Other Ranking Metrics

How Normalized Discounted Cumulative Gain compares to alternative ranking evaluation metrics across key properties for recommender system evaluation.

PropertyNDCGPrecision@KRecall@KMRR

Handles graded relevance

Position-aware weighting

Normalized across queries

Binary relevance only

Sensitive to total relevant count

Penalizes relevant items at bottom

Ideal for multi-level labels

METRIC DEEP DIVE

Frequently Asked Questions

Precise answers to the most common technical questions about Normalized Discounted Cumulative Gain, its calculation, and its role in evaluating ranking quality.

Normalized Discounted Cumulative Gain (NDCG) is a ranking quality metric that measures the usefulness of a ranked list by giving higher weight to relevant items appearing at the top positions and normalizing the score against an ideal ranking. It works by first computing the Discounted Cumulative Gain (DCG), which sums the graded relevance scores of each item in the list, applying a logarithmic discount factor based on position so that highly relevant items ranked lower contribute less to the total. This DCG is then divided by the Ideal DCG (IDCG)—the DCG of the perfectly ordered list where all items are sorted by descending relevance—yielding a normalized score between 0 and 1. An NDCG of 1.0 indicates a perfect ranking. The metric is widely used in information retrieval and recommender systems because it handles graded relevance (e.g., 0-4 scale) rather than binary judgments, making it sensitive to varying degrees of usefulness.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.