For the record you can only spend 30 days maxium in jail, unless you someone pays bail. Next jail is the place you are held before your trial so you don't flee the country. Next he goes in and the charges are placed against him where he either pleads not guilty or guilty, if he pleads guilty he goes straight to prison, if he pleads not guilty he goes back the jail to wait for part 2 of his trial and must get a lawyer to defend him or he must defend himself. Part 2 if the actual trial part we see on tv, but it's less dramatic and usually end within an hour. If he is found innocent he goes free, if he is found guilty he goes back to jail for part 3. In part 3 he goes back to court where the judge tells him his sentence and for each victim it adds a couple of years to that sentence. The he goes to prison for x amount of time.
Now it also true that we have people in jail for really long time and that is because of prison over population, so now you see jails being used as makeshift prisons which is also illegal by the way because they are only for temporary storage. Also for each extra day in jail is taken off your sentence.