Bail occurs when a judge ends the incarceration of an individual upon receiving a security, usually a sum of money. If you were paying your own bail you (or the person who paid for you) would get all monies back so long as you attended all court appearances.
In the American Legal System, bail is the primary way to secure the freedom of someone who has allegedly committed a crime and has subsequently been incarcerated. Bail gives the defendant time to hire a lawyer and prepare a defense without restriction.
Note: bail is surety, not a punishment for a crime.