Dungeons and Dragons has generally always been in a medieval European setting (there are execeptions like Darksun and Ebberon) but one with magic, gods, monsters etc. In actual medieval Europe though, literacy was extremely low according to this article. However, I've never had the impression that NPCs in game are unable to read or write. The monster manual states this about creatures and languages:
The languages that a monster can speak are listed in alphabetical order.
That only covers being able to speak languages though. I don't see it stated specifically that any given creature can read and write in any languages they might know.
So should I assume that an NPC can read and write in any language they know?
Best Answer
Do what works for your world
As far as I can find, the rules don't say much (if anything) about the prevalence of the ability to either read or write in the world. You should instead do whatever makes sense for your world and keep this in mind when designing it.
I was able to find various quotes from the DMG, PHB, and MM that are about languages, but none of these feel especially important or insightful to me for the question you've posed:
For me, the quote that best exemplifies the ability to make the world your own is this:
Who is taught how to read and write, and how prevalent such a skill is, is up to the world of the GM. This is similar to how the GM can design how fantastical, how magical, how gritty, and so on, their world is. Similarly, you can design how literate your world is. When designing worlds, you should consider things like spell scrolls and wizard's spellbooks and other similar complications that might come up when having these skills be scarce.
Personally, I have found assuming everybody to be literate to be easiest on myself. I don't have a fantastic understanding of the real-life experience of medieval times, I instead have a fantastic understanding of the real-life experience of modern, 1st-world times. I know a lot more about how interactions and correspondences work in a literate world than in a predominantly illiterate one and can use what I do know in designing my world. The alternatives, for me, would either be outright guessing, or extreme amounts of research, and (usually) neither appeals to me and so my worlds have high levels of literacy.