Normalized discounted cumulative gain (NDCG) is a ranking metric that measures how well a system orders results by graded relevance, giving more credit to relevant items that appear near the top of the list and scaling the score to a range from 0 to 1. Within Retrieval & knowledge, NDCG is the standard way to evaluate search engines, rerankers, recommender systems and the retrieval stage of RAG pipelines.
Unlike binary metrics such as Precision@k, NDCG accepts multiple relevance levels, for example 0 for irrelevant, 1 for partially relevant and 3 for highly relevant. It is usually reported at a cutoff, written as NDCG@k, such as NDCG@10.
How NDCG is calculated
NDCG is computed in three steps: gain, discount and normalization. Each result receives a gain derived from its relevance grade, each gain is divided by a logarithmic position discount, and the resulting sum is divided by the best sum achievable for the same query.
The discounted cumulative gain (DCG) at cutoff k adds the discounted gains of the first k results. The common formulation uses gain = 2^rel - 1 and discount = log2(i + 1), where i is the rank position. The ideal DCG (IDCG) is the DCG of the same judged items sorted perfectly by relevance, and NDCG@k = DCG@k / IDCG@k.
The table below shows how the position discount reduces the weight of lower-ranked results.
| Rank position | Discount log2(i + 1) | Weight of a result |
|---|---|---|
| 1 | 1.00 | 100% |
| 2 | 1.58 | 63% |
| 3 | 2.00 | 50% |
| 5 | 2.58 | 39% |
| 10 | 3.46 | 29% |
Because the discount grows slowly, NDCG still values results deep in the list, but a highly relevant document at rank 1 contributes more than three times as much as the same document at rank 10.
A short worked case shows the mechanics. Suppose a query returns three results graded 3, 0 and 2. With exponential gain, the DCG@3 is 7/1.00 + 0/1.58 + 3/2.00 = 8.50. The ideal order is 3, 2, 0, giving an IDCG@3 of 7/1.00 + 3/1.58 + 0 = 8.89. The resulting NDCG@3 is about 0.96, which signals a nearly ideal ranking despite the irrelevant item in second place.
Gain functions and relevance grades
The choice of gain function changes what NDCG rewards. The exponential gain 2^rel - 1 strongly favors highly relevant documents, while linear gain treats each relevance step as equal. Libraries differ in their defaults, so two NDCG values are comparable only when they use the same gain and discount.
| Relevance grade | Meaning | Linear gain | Exponential gain |
|---|---|---|---|
| 0 | Irrelevant | 0 | 0 |
| 1 | Marginally relevant | 1 | 1 |
| 2 | Relevant | 2 | 3 |
| 3 | Highly relevant | 3 | 7 |
Relevance grades come from human judgments, click models or, increasingly, LLM-based relevance labeling. The labeling guideline matters as much as the formula: inconsistent judges produce noisy NDCG differences that can exceed the effect of a model change.
The metric was introduced by Järvelin and Kekäläinen for information retrieval research, and the exponential-gain variant later became popular in learning-to-rank work at web search companies. Some implementations also discount the first position, while others leave it undiscounted, so documentation of the exact variant used belongs in every evaluation report.
How NDCG compares with other ranking metrics
NDCG is the preferred metric when relevance is graded and order matters. Other metrics answer narrower questions and are often reported alongside it.
| Metric | Relevance type | Position-aware | Best suited for |
|---|---|---|---|
| NDCG@k | Graded | Yes, logarithmic | Overall ranking quality |
| Mean reciprocal rank | Binary | First relevant only | Single-answer lookups |
| Recall@k | Binary | No | Candidate generation for reranking |
| Precision@k | Binary | No | Share of useful results on a page |
| Mean average precision | Binary | Yes | Many relevant documents per query |
Benchmarks such as BEIR and the retrieval tasks of MTEB use NDCG@10 as the headline metric, which is why embedding models and rerankers are commonly compared on that number.
Using NDCG to evaluate retrieval and RAG systems
In practice, NDCG is averaged over a query set, and the cutoff k should match how results are consumed. A RAG pipeline that passes five chunks to a language model is better evaluated with NDCG@5 than with NDCG@100.
| Scenario | Recommended setup | Reason |
|---|---|---|
| Web or site search page | NDCG@10 | Matches a typical first page |
| RAG context selection | NDCG@k with k equal to chunks passed | Measures what the model actually sees |
| Reranker evaluation | NDCG@10 plus Recall@100 of first stage | Separates reranking from candidate recall |
| Recommendation feed | NDCG@k with engagement-based grades | Reflects graded user interest |
Teams should also report confidence intervals or significance tests, because NDCG differences of one or two points on a few hundred queries are often within statistical noise.
Limitations and common mistakes
NDCG is robust but easy to misuse. Its normalization hides absolute quality differences between queries, and its result depends heavily on which documents were judged.
- Unjudged documents treated as irrelevant penalize new systems that retrieve good but unlabeled results.
- Computing IDCG only from retrieved items inflates scores; the ideal ranking should use all judged documents for the query.
- Queries with no relevant documents make IDCG zero; they must be excluded or handled explicitly.
- Mixing gain functions or cutoffs across experiments makes numbers incomparable.
- A high NDCG does not guarantee answer quality in RAG, because generation can still ignore or misread good context.
Put simply
Imagine asking a librarian for books on a topic. A good librarian hands over the best books first. NDCG gives a score for how good that order is.
Each result earns points for being useful. Results near the top count fully. Results lower down count less. The total is then compared with a perfect order. A score of 1 means the order was ideal, and a lower score means good results were buried.
In practice
An internal support team builds a RAG assistant over 40,000 help-center articles. The engineers collect 300 real employee questions and ask two reviewers to grade the top 20 retrieved passages per question on a scale from 0 to 3.
The baseline, a BM25 search over article chunks, reaches an NDCG@5 of 0.52. Adding a dense embedding model in a hybrid search raises it to 0.61, and adding a cross-encoder reranker raises it to 0.71. A bootstrap test confirms that both gains are statistically reliable.
Because the assistant passes five passages to the language model, the team tracks NDCG@5 as the release gate. Answer accuracy in a separate review rises from 64% to 78%, which supports the link between better ranking and better answers.