What to Know
Can and may are both used to talk about permission. Using can in this sense isn't incorrect but it is considered informal. If you want to sound formal, use may.
We all know the joke (or, rather, “joke”): a student raises their hand and asks the teacher “Can I go to the bathroom?” and the teacher responds, “I don’t know—can you?”
The “joke” here is based on the insistence that you should use may when asking for permission to do something, and can when speaking about ability. By this logic, the student should have said “May I go to the bathroom?” since their ability to use the facilities is likely not in question.
But the reality of the situation is that both can and may have been used historically to refer to permission and continue to be used so today. How did we end up in this situation?
Origin and Meaning of 'May'
May is the earlier verb, showing up in manuscripts from the 8th century. It originally referred to having strength or power, and then very quickly developed a meaning that referred to ability. This particular meaning is no longer in current use, but we find a late representative of this use in Chaucer’s Canterbury Tales from 1395: “We mowen nat...It ouertake, it slit awey so faste” (“We may not overtake it, it slid away so fast”). May also developed a meaning referring to possibility, which we’re still familiar with today (“I may be able to have lunch with you this Thursday”), and the meaning that schoolteachers insist it has today–one that grants permission (“You may use the bathroom”). All four of these meanings were in use before 1000AD.
Overlap with 'Can'
Around that time, can came on the scene. It was a verb that originally meant “to know,” and then “to know how to do something,” and then “to have the ability to do something.” This last meaning, which showed up around 1300, was can’s first semantic overlap with may. The overlap continued: by 1500, both can and may were used to refer to ability and possibility.
Given that there was already some overlap between the two words, it’s not surprising that by the end of the 1800s, can also came to mean “to have permission.” (If there’s anything surprising in that, it’s perhaps that it took so long for can to copy that meaning of may’s.)
It didn’t take too long for teachers and grammarians of the day to proscribe that can should only be used of ability and may of permission. We find the rule spelled out clearly (complete with a fictional student-teacher exchange) in Charles Lurie’s 1926 How To Say It: Helpful Hints On English. There is no particular reason for the rule, except for the fact that may has been used longer to mean “to give permission” than can has. Nonetheless, the “rule” lives on.
In reality, can likely has more use in the “permission” sense than is recorded, as it is more informal and so shows up in speech more frequently than may does. May is the more formal word, and if you are at all concerned about being tut-tutted, a safe choice. Can is now the verb of choice for ability, and both can and may are still used in the "possibility" sense. You may use can if you wish, and you can use may if it makes you feel better.