Bin number convention

I have a question concerning the numbering convention of bins in histograms. Here a little extract from the root manual, v5.08, page 26:

Bin Numbering Convention

For all histogram types: nbins, xlow, xup
Bin# 0 contains the underflow.
Bin# 1 contains the first bin with low-edge (xlow INCLUDED).
The second to last bin (bin# nbins) contains the upper-edge (xup EXCLUDED).
The Last bin (bin# nbins+1) contains the overflow.

The last two lines describe both a “last bin”. Which is the last bin now? And do I have to set up “nbins+2” bins in my histogram creator in reality if I want to have “nbins” bins with data, cause of the under- and over flow (which would give me another two bins)? The convention is a little bit confusing, at least for me. Could some one maybe bring a little bit light in here?


see : “Convention for numbering bins” at


ok, this helps me more. when I look at this right, bin 0 and nbins+1 are not of a greater interest to me but to know that they contain the under-/overflows.
but when setting bin contents of a histogram via doing a loop over the bins, instead of doing a loop from i=0 to i<nbins I should do a loop from i=1 to i=nbins, right?

thanks for the quick responce,

It’s a bit confusing when you use for loop to fill an histogram. The bin convention on ROOT website, for me, is confusing as well.

When you create an histogram using:
TH1F* h1= new TH1F( name,title,nbinsx,xlow,xup);
TH1F* h1= new TH1F( "h1 ", “title”, 5 , 0 , 5 ); for instance;
You got 5 bins with width of 1 as you set it up, but boarder of bins start from 0-1, 1-2, 2-3, 3-4, 4-5 . Thus, each individual bin has lower and upper edges. Plus, they have centre values. Now, if you want to fill 1st bin with a number, you do h1->Fill(0., 20.); . Please, do try on by writing these lines one by one on a terminal. You actually typed 0 for bin number in fill() function, but you filled the 1st bin. If you want to fill all the bins by “for-loop” at once,
your “for-loop” has to start from 0 as below:

for(int i=0 ; i < 5 ; i++){
h1->Fill(i, i+20);

Plus, when filling the 1st bin, you say h1->Fill(0,20), for example, but when you call the bin content, you type h1->GetBinContent(1).
I hope, I am all correct because I tried before I typed here. Thus, it should work. I feel like I should not bother with overflow concept at all.

Maybe, I should ask, under what condition, I come a cross with overflow thing?

Sincerely yours.

Actually, your histogram has 7 bins. The bin number 0 is the “underflow bin” (x < 0.0), the bin number 1 is 0.0 <= x < 1.0, …, the bin number 5 is 4.0 <= x < 5.0 and the bin number 6 is is the “overflow bin” (x >= 5.0).