Bail exists to help balance the justice system. The purpose of bail is to let recently arrested defendants leave police custody and jail so they can return home to their loved ones and go back to work, spend time with family, and go about as much of their regular life as possible. It is not always fair to make all defendants remain in jail for weeks, months, even a year or more as their trial lingers on since they have yet to be found guilty or innocent. If they are innocent, spending all that time in jail would be a major human rights violation. If they are guilty, then they will do their time in prison, without the opportunity to bail out then.
Some defendants are denied the chance to bail on very extreme and serious circumstances; like having committed multiple heinous crimes and thus posing as a huge threat to the public. Denying bail to dangerous individuals is done to protect the community.