 If a defendant spent time in custody while awaiting his trial (that is, he was not released on bail), the judge is allowed to take that into account when determining the sentence.There used to be no specific formula, and historically judges generally gave a "2 for 1" credit for pre-trial custody.This was subsequently changed by legislation.