A method for encoding video data, the method comprising: encoding samples of a largest coding unit of a picture using a sample adaptive offset mode which comprises a band offset mode, wherein encoding the samples of the LCU using the SAO mode comprises: iteratively arithmetically right shifting the original samples of a component plane of the LCU to classify the original samples into a bin of a 32-bin histogram; terminating the iterative classification when either all samples belonging to the component plane have been classified, or a number of samples belonging to one of the 32 bins of the histogram is greater than or equal to half a number of samples belonging to the component plane of the LCU; selecting a group of four consecutive bins starting with a bin having the greatest number of samples; calculating differences between corresponding reconstructed samples of the LCU and original samples of the LCU belonging to the selected group of consecutive bins; clipping a number of bits from each of the differences to form clipped differences which have a first specified number of bits and fall within a respective range of values; summing the clipped differences to form a sum of differences for each bin belonging to the selected group; clipping a number of bits from each sum of differences to form a clipped sum of differences which has a second specified number of bits and falls within a respective second range of values; calculating a number of the reconstructed samples for each bin belonging to the selected group; clipping a number of bits from each number of reconstructed samples to form a clipped number of samples which has a third specified number of bits and falls within a respective third range of values; and dividing each clipped sum of differences by the respective clipped number of samples to produce an offset for each bin belonging to the selected group for the LCU. iteratively arithmetically right shifting the original samples of a component plane of the LCU to classify the original samples into a bin of a 32-bin histogram; terminating the iterative classification when either all samples belonging to the component plane have been classified, or a number of samples belonging to one of the 32 bins of the histogram is greater than or equal to half a number of samples belonging to the component plane of the LCU; selecting a group of four consecutive bins starting with a bin having the greatest number of samples; calculating differences between corresponding reconstructed samples of the LCU and original samples of the LCU belonging to the selected group of consecutive bins; clipping a number of bits from each of the differences to form clipped differences which have a first specified number of bits and fall within a respective range of values; summing the clipped differences to form a sum of differences for each bin belonging to the selected group; clipping a number of bits from each sum of differences to form a clipped sum of differences which has a second specified number of bits and falls within a respective second range of values; calculating a number of the reconstructed samples for each bin belonging to the selected group; clipping a number of bits from each number of reconstructed samples to form a clipped number of samples which has a third specified number of bits and falls within a respective third range of values; and dividing each clipped sum of differences by the respective clipped number of samples to produce an offset for each bin belonging to the selected group for the LCU.