The Bible identifies three kinds of slaves—female Hebrew, male Hebrew, and non-Hebrew—and these were treated differently.
Male Hebrew slaves were to be released after six years and were treated better. In general, the code for fellow Israelites involved a crude social safety net to prevent extreme and unnecessary hardship; so, if one managed to get into serious financial trouble to the point of being homeless, he could be "debt bound" to another Israelite. While easily translated as "slavery", it was more like getting someone to come work for you for free... oh, wait, that is "slavery". Evangelical Christians, especially those who subscribe to Biblical inerrancy, will commonly emphasize this distinction between debt bondage and race-based chattel slavery when excusing the Bible for endorsing "slavery"; the argument is that it's not real slavery, at least by 19th Century American standards, although this is arguably a distinction without (much of) a difference.
Female Hebrews could be sold by their fathers and enslaved for life (Exodus 21:7-11), but under some conditions.
Finally, according to Leviticus 25:44, non-Hebrews could be subjected to "slavery" in exactly the way that it is usually understood—the slaves could be bought, sold and inherited when their owner died. This, by any standard, is race- or ethnicity-based, and must necessarily involve some sort of slave trade.
Two types of slavery: indentured servitude and full chattel slavery
So the Bible endorses two types of slavery: indentured servitude and full chattel slavery - both are bad, but the latter worse.
Beating slaves was perfectly allowable under the following rules:
(Exodus 21:20-21 ESV) When a man strikes his slave, male or female, with a rod and the slave dies under his hand, he shall be avenged. But if the slave survives a day or two, he is not to be avenged, for the slave is his money.
(Exodus 21:26-27 ESV) When a man strikes the eye of his slave, male or female, and destroys it, he shall let the slave go free because of his eye. If he knocks out the tooth of his slave, male or female, he shall let the slave go free because of his tooth.
Male Hebrew slaves
From Exodus 21:2:
“If you buy a Hebrew servant, he is to serve you for six years. But in the seventh year, he shall go free, without paying anything. If he comes alone, he is to go free alone; but if he has a wife when he comes, she is to go with him. If his master gives him a wife and she bears him sons or daughters, the woman and her children shall belong to her master, and only the man shall go free. But if the servant declares, ‘I love my master and my wife and children and do not want to go free,’ then his master must take him before the judges. He shall take him to the door or the door-post and pierce his ear with an awl. Then he will be his servant for life.
It is interesting to note that if a slave wishes to remain with his wife and family he must submit to his master for life.
On the other hand Hebrew slaves - and only those Hebrew slaves who entered slavery "voluntarily" - got some severance package as described in Deuteronomy 15:12:
If any of your people—Hebrew men or women—sell themselves to you and serve you six years, in the seventh year you must let them go free. And when you release them, do not send them away empty-handed. Supply them liberally from your flock, your threshing floor and your winepress. Give to them as the Lord your God has blessed you. Remember that you were slaves in Egypt and the Lord your God redeemed you. That is why I give you this command today.
Female Hebrew slaves
Female Hebrew slaves were to be treated differently from males. Parents could sell their daughters into slavery. (Exodus 21:7-11 NLT)
When a man sells his daughter as a slave, she will not be freed at the end of six years as the men are. If she does not please the man who bought her, he may allow her to be bought back again. But he is not allowed to sell her to foreigners, since he is the one who broke the contract with her. And if the slave girl's owner arranges for her to marry his son, he may no longer treat her as a slave girl, but he must treat her as his daughter. If he himself marries her and then takes another wife, he may not reduce her food or clothing or fail to sleep with her as his wife. If he fails in any of these three ways, she may leave as a free woman without making any payment.
If the Israelites wanted full slaves they were instructed in Leviticus 25:
Your male and female slaves are to come from the nations around you; from them you may buy slaves. You may also buy some of the temporary residents living among you and members of their clans born in your country, and they will become your property. You can will them to your children as inherited property and can make them slaves for life, but you must not rule over your fellow Israelites ruthlessly.
Slavery in the New Testament
The New Testament makes no condemnation of slave ownership but does have advice for Christian slaves and also regulates how Christian slave owners should treat the slaves they own.
(Ephesians 6:5 NLT) Slaves, obey your earthly masters with deep respect and fear. Serve them sincerely as you would serve Christ.
Christian slaves whose masters were also Christian are told:
(1 Timothy 6:1-2 NLT) Christians who are slaves should give their masters full respect so that the name of God and his teaching will not be shamed. If your master is a Christian, that is no excuse for being disrespectful. You should work all the harder because you are helping another believer by your efforts. Teach these truths, Timothy, and encourage everyone to obey them.
There are instructions for Christian slave owners to treat their slaves well.
Eph 6:9 ) And masters, treat your slaves in the same way. Do not threaten them, since you know that he who is both their Master and yours is in heaven, and there is no favouritism with him. (See also Ephesians 6:7-8)
(Coll 4:1 ) Masters, provide your slaves with what is right and fair, because you know that you also have a Master in heaven.
Nevertheless in other parts of the New Testament slave traders (i.e. those who kidnapped and sold people as slaves) were considered "lawless and rebellious," and categorized with homosexuals, liars and promise breakers (though even they were not lumped together with tax collectors.)
"(1Timothy 1:9-10 NLT) For the law was not intended for people who do what is right. It is for people who are lawless and rebellious, who are ungodly and sinful, who consider nothing sacred and defile what is holy, who kill their father or mother or commit other murders. The law is for people who are sexually immoral, or who practice homosexuality, or are slave traders, liars, promise breakers, or who do anything else that contradicts the wholesome teaching that comes from the glorious Good News entrusted to me by our blessed God."
This is probably one of the clearest example of religious moral relativism.
Most modern Christians prefer to avoid, or are unaware of, these sections of the Bible. If forced to explain Biblical justification for slavery, they may come up with something, but fortunately Christians as a group think it would be wrong to reintroduce slavery. Christian attempts to justify what is in the Bible can lead to them sanctioning things that most moral humanists, and even most Christians, would say are wrong.