The court in a criminal case has the discretion to give the defendant credit for the time they have already spent in jail pending bail or trial
Most agree that having to spend time waiting in jail for one’s trial to start, or pending release until and if bail is granted offends one’s sense of fairness and due process. Especially since it is a fundamental right for the accused to be presumed innocent within our system of justice.
For these reasons, judges will often reduce the formal sentence by the time the defendant was waiting in jail pending trial or the setting of bail.