Well . . . it depends on the colony (or the state) and the year.
During the colonial period in Virginia, no laws prohibited teaching slaves to read. In fact, Samuel Davies, a Presbyterian minister, worked hard to bring books and education to Virginia slaves in the middle of the 1700s. Not only was it legal, there were some free schools set up to teach African-American children. In Williamsburg, Virginia, Mrs. Ann Wager operated a school for black children from 1760 until her death in 1774. A widowed teacher, she was hired to instruct young slave children by the Bray Associates, a group of English philanthropists who paid the expenses. The Bray School, as it was called, existed specifically to “instruct Negro Children in the Principles of the Christian Religion.”
There were other Bray Schools, one in Philadelphia that Benjamin Franklin praised for its good work. Nor were its students limited to boys, as was the case down the street at Williamsburg’s all-white, all-male College of William and Mary. The Bray Associates anticipated that girls would be taught as well as boys, and directed the hiring of a female teacher. “As tis probable that Some of Each Sex may be sent for Instruction, The Associates are therefore of the opinion that a Mistress will be preferable to a Master, as she may teach the Girls to Sew knit, &c. as well as all to read & say their Catechism. They think 30 Children or thereabout will Sufficiently employ one person.” Notice they thought that the girls could learn what the boys were learning, plus sewing and knitting.
Enrollment lists show that most students at the Bray School were enslaved, however, a few free black children also attended the classes which were held in Mrs. Wager’s home. The Bray School was one of several such establishments in the American colonies set up for educating African-American children. A Virginia churchman noted in 1750 that he sometimes visited three schools for blacks in his parish and hoped there would be one in every parish in the colony. Even so, the majority of slaves received no schooling at all.
But colonies differed. In colonial South Carolina, teaching a slave to write was made illegal in 1740, the year after the Stono Rebellion. Georgia passed a similar law in 1755. Teaching them to read was not specifically outlawed, since writing was the worry. Slaves who could write could communicate plans for rebellion more easily. But in most colonies, north and south, educating slaves was up to the owner.
During the 19th century, most Southern states passed laws prohibiting the education of African Americans, whether slave or free. In 1831, the Nat Turner uprising so frightened slaveholders everywhere that a slew of new laws were enacted to clamp down on slave activities. One of those laws prohibited teaching African Americans to read and write so they could not easily communicate to plan rebellion. In 1833 Alabama tried to cover all bases with its law that fined anyone who taught a slave or free person of color to read, write, or spell. Nonetheless, before this date and after it, there were many examples of literate African Americans, although never a great percentage. As historian Linda Rowe writes, education was considered by some to be “an instrument of conversion to Christianity for slaves,” and for that reason, encouraged.
Interestingly, in The Grandees of Government: Origins and Persistence of Undemocratic Politics in Virginia (2013), historian Brent Tarter debunks a pervasive myth. “A few months before the [Nat Turner] rebellion the [Virginia] assembly made it a criminal offense for any person to receive a salary for instructing enslaved people how to read and write, and it also made it a criminal offense for ‘any white person or persons’ to ‘assemble with free negroes or mulattoes, at any school-house, church, meeting-house, or other place for the purpose of instructing such free negroes or mulattoes to read or write.’ The state’s laws did not, as popularly believed, make it illegal for people to teach their own property to read and write.” [my emphasis] So in Virginia, at least, state law did not prevent a master from educating his own slaves.
Before the Civil War, historians estimate that about 10% of African Americans could read. Immediately after the war, that number jumped to 30% as freed slaves, young and old, rushed to learn.
Generally speaking, teaching African Americans to read and write was usually legal in the colonies and American states before 1830. After that, it was usually illegal.