So in my 5e campaign, the players will be studying under the Guildmaster of each of their classes. Each Guildmaster is the head of all the guilds in the country, so they'd be pretty badass. They work directly under the king.
My question is, what level would someone who has dedicated their entire life to their class and has become a respected leader be? Obviously they won't be lower level like five or something, and 20 seems a little too high. They aren't gods or anything, just some of the best in their fields.
Is there anything that tells what level an extremely experienced NPC would be? Is there a way to find out how many years of training an NPC would need to be a certain level?
There is no guideline for this. D&D doesn't contain the idea of spending years in training to improve, and lacking any such training rules there's no way to guesstimate the power of a character based on their years of experience in a given role.
You really don't need a guideline for this, anyway. D&D hands the DM the job of determining non-player character power levels according to what is useful for the game, rather than what is "realistic" (for some value of realism). Pick a number that seems about right, and make them that level. You already have a sense of what would be too low or too high; and other than choosing a number you've already decided would be a bad choice, you can't really choose this number wrong.
Pick a number. Build the NPC (using either monster rules or PC rules, per the DMG's advice on page 282). There's your Guildmaster!
The game really does not care about this detail very much, and whatever you choose will not cause the game any problems. The only way your choice could ever be 'wrong' is if your Guildmasters end up not who you want them to be, so it's entirely on you to decide what is right for your needs. I would personally think first on how long I want them to be better than the PCs, or conversely how quickly I want the student to surpass the master, and then pick a number that very roughly feels like it suits. Your goals may be different, so follow the logic of your own needs.