Inferensys

Glossary

Normalized Discounted Cumulative Gain (NDCG)

Normalized Discounted Cumulative Gain (NDCG) is a metric that measures the quality of a ranked list of search results by giving higher weight to relevant documents appearing earlier, normalized against an ideal ranking.
Developer reviewing semantic search engine results on laptop, relevance scores visible, technical search demo.
RANKING QUALITY METRIC

What is Normalized Discounted Cumulative Gain (NDCG)?

A metric that measures the ranking quality of search results by giving higher weight to relevant documents appearing earlier in the list, normalized against an ideal ranking.

Normalized Discounted Cumulative Gain (NDCG) is a measure of ranking quality that evaluates a ranked list of results by summing the graded relevance of each document, logarithmically discounted by its position, and then normalizing this score against the maximum possible DCG for that query. Unlike binary metrics, NDCG handles multi-level relevance judgments, making it the standard for evaluating search engines and recommendation systems where some documents are more useful than others.

The calculation involves three core components: Cumulative Gain (CG), the raw sum of relevance scores; Discounted Cumulative Gain (DCG), which penalizes relevant documents that appear lower in the ranking via a logarithmic discount; and the final normalization step, where the achieved DCG is divided by the Ideal DCG (IDCG)—the DCG of a perfectly ordered list. This normalization yields a score between 0 and 1, enabling meaningful comparison across queries with varying numbers of relevant results.

RANKING QUALITY METRIC

Key Characteristics of NDCG

Normalized Discounted Cumulative Gain (NDCG) is the gold-standard metric for evaluating ranking quality in search and recommendation systems. It measures how well a system orders results by prioritizing highly relevant items at the top while penalizing relevant items buried deep in the list.

01

Position-Aware Discounting

NDCG applies a logarithmic discount function to penalize relevant documents that appear lower in the ranked list. The discount for position p is typically 1 / log₂(p + 1), meaning a highly relevant document at rank 1 contributes fully, while the same document at rank 10 contributes only about 29% of its original value. This mirrors real user behavior—searchers rarely scroll past the first page of results. The cumulative gain is the sum of these discounted relevance scores across all positions, ensuring the metric rewards systems that front-load the most valuable content.

02

Ideal Ranking Normalization

The 'Normalized' in NDCG divides the system's DCG score by the Ideal DCG (IDCG)—the DCG achieved by a perfect ranking where all documents are sorted in descending order of relevance. This normalization serves two critical purposes:

  • Cross-query comparability: Scores fall between 0.0 and 1.0 regardless of result set size
  • Fair evaluation: Queries with many highly relevant documents don't artificially inflate scores An NDCG of 1.0 indicates the system produced the theoretically optimal ordering for that query.
03

Multi-Graded Relevance Judgments

Unlike binary metrics such as Precision@K, NDCG supports graded relevance labels that capture varying degrees of usefulness. Common grading schemes include:

  • 0: Not relevant
  • 1: Marginally relevant (tangential topic)
  • 2: Relevant (answers the query partially)
  • 3: Highly relevant (definitive answer)
  • 4: Perfectly relevant (navigational intent, exact match) This granularity allows NDCG to distinguish between a system that returns ten 'marginally relevant' documents versus one that returns three 'highly relevant' ones—a distinction binary metrics completely miss.
04

Cutoff-Based Evaluation (NDCG@K)

NDCG is commonly computed at specific cutoff points—NDCG@5, NDCG@10, NDCG@20—to evaluate ranking quality within the viewport users actually see. NDCG@10, for instance, only considers the top 10 results, making it the de facto standard for web search evaluation. This cutoff approach acknowledges that users rarely paginate deeply, so ranking quality beyond position 20 has diminishing practical importance. Different applications use different cutoffs: e-commerce product search might optimize for NDCG@5, while academic literature search might use NDCG@20 or higher.

05

Gain Functions and Exponential Weighting

The 'Gain' component can use either linear gain (gain = relevance_label) or exponential gain (gain = 2^relevance_label - 1). Exponential gain dramatically amplifies the value of highly relevant documents. Under exponential gain, a document with relevance 4 contributes 15 points, while relevance 1 contributes only 1 point—a 15:1 ratio versus 4:1 under linear gain. This is critical for navigational queries where only the single most relevant result matters. The choice of gain function should align with the application's tolerance for partially relevant results.

06

Relationship to Other Ranking Metrics

NDCG sits within a family of ranking evaluation metrics, each with distinct properties:

  • Mean Reciprocal Rank (MRR): Only cares about the position of the first relevant document; ignores all others
  • Mean Average Precision (MAP): Uses binary relevance and averages precision at each relevant document's position
  • NDCG: Combines graded relevance with position discounting and normalization NDCG is generally preferred over MAP when relevance judgments are graded rather than binary, making it the standard for modern search systems where nuanced relevance distinctions matter.
METRIC COMPARISON

NDCG vs. Other Ranking Metrics

A comparative analysis of NDCG against other common offline evaluation metrics for ranked retrieval, highlighting their sensitivity to graded relevance and rank position.

FeatureNDCGMRRPrecision@KMAP

Handles Graded Relevance

Penalizes Low-Rank Relevant Docs

Normalized for Query Difficulty

Sensitive to Total Number of Relevant Docs

Primary Use Case

Graded relevance ranking

First relevant result

Top-K set quality

Binary relevance ranking

Score Range

0.0 to 1.0

0.0 to 1.0

0.0 to 1.0

0.0 to 1.0

Computational Complexity

O(n log n)

O(n)

O(k)

O(n log n)

Ideal For

E-commerce, informational search

Known-item search, Q&A

Recommendation carousels

Ad-hoc retrieval benchmarks

RANKING QUALITY METRICS

Frequently Asked Questions

Clear, technical answers to the most common questions about Normalized Discounted Cumulative Gain (NDCG) and its role in evaluating search and recommendation systems.

Normalized Discounted Cumulative Gain (NDCG) is a metric that measures the quality of a ranked list of results by comparing the gain from the system's ranking against the gain from an ideal ranking. It works by first calculating the Cumulative Gain (CG) , which is the sum of relevance scores for all documents in the result set. It then applies a discount function (typically a logarithmic decay) to penalize relevant documents that appear lower in the ranking, producing Discounted Cumulative Gain (DCG) . Finally, this DCG is normalized by dividing it by the Ideal DCG (IDCG) —the DCG of a perfectly ranked list—yielding a score between 0 and 1. This normalization allows for meaningful comparisons across different queries and result sets of varying lengths, making NDCG the standard metric for evaluating graded relevance in search engines and recommender systems.

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.