A lot of answers here are basically saying, everyone around you is probably not stupid. But I think there is a real possibility that everyone around you really is stupid relative to you, so I'm going to assume sincerity and take the question on its face.

One of the ways this feeling comes up for me is when I realize that almost no one is actually engaging in actual thought in order to solve specific problems. First you have maybe 90% of people who are just collecting a paycheck, or trying to maintain social harmony, or playing empire-building games, or in general playing a game that is a different game from building good things and figuring out the truth. Of the remaining, most people think using metaphors, heuristics, social consensus and other forms of indirect thought. Very few people have the ability to squint and stare directly at a problem and engage with the subject itself in a high-decoupling "autistic" way.

If you have this ability to take a problem, break it down into first principles and just think hard about it until you find a solution, most everyone will probably seem stupid to you, because they are not doing that. Sometimes you watch two people argue about something and understand within ten seconds what the central point is and you want to shake them both and make them just address that directly, but instead you listen to them ramble on for another hour. Sometimes you watch people stand around being puzzled by some bug, and then you go in, actually investigate the thing itself, build an understanding of what is happening and what exactly is going wrong and push a fix in half an hour. Sometimes the truth about a topic is just obvious to you if you stare at it with laser vision and ignore all irrelevant considerations and then you wonder why it isn't obvious to everyone else.

It may not even necessarily be an intelligence thing. Raw brainpower may be a prerequisite but it is more of, I guess, an actually-thinking-about-the-thing-itself thing. My raw IQ is probably not that high but I make up for it by spending a lot of time thinking and caring a lot about the truth to the exclusion of everything else. Then I wonder why other people don't do this.

The feeling of frequently being the only person in the room doing this is very isolating, and people in this position seem to end up with either super high or super low self esteem. I was the latter. I felt like I would never be able to communicate with or relate to anyone and that society would always see me as a loser, and it took a lot of time for me to overcome this. Nowadays I have a personal project that I believe in, that I can apply all of my problem-solving skills to, and I have a strong sense of the things I value and have specific tracks/plans to further each of them. I’m at peace with my psychological profile and have accepted my path in life. (If you’re one of the ones with high self esteem, you can fortunately skip this whole section.)

On to the practical side of things… society heavily pushes the message that no matter what, you will inevitably have to deal with people on some level. I think this is true and that there's no use fighting it. Everyone has people they can’t get along with; for you that list may simply be bigger. But also, I think that social interaction can be a tricky thing and there are many mental traps to fall into here. For example, you may believe that you just want to be left alone or not have to deal with anyone, but then you get what you asked for, and your all-too-human brain rebels and you realize social interaction is healthy after all. Or you may adopt a cynical view where you view human interaction as “just saying the right things” or “playing the game” to get along with others, and it works for a while because you are smart, but then you realize how ultimately unsatisfying it is. The point I'm making is that humans have a complicated relationship with other humans (or at least I do), and it can take lots of trial and error to figure out what kind of interface with others will make you happiest.

What worked for me was to figure out and be explicit about the type of relationship I’m able/willing to have with each person. I can usually tell based on what they say, what beliefs/values they express, how they behave, etc how well I can get along with them, and then I keep them at the right distance accordingly. I have acquaintances, activity friends, shared-ideology friends, and close/"real" friends. The “stupid” people in your question usually get pushed to acquaintance or activity friend.

Work is trickier. I am a terrible employee so I don’t really have good advice here. I kind of cheated and just went the self-employment route. I have a part-time contract gig that pays the bills and then I spend the rest of my time working on my own project. My coworkers for the most part are also just trying to pay the bills so I have a pretty good shared understanding and working relationship with them. I carefully structured my life so that I don’t depend on what you call “stupid people” for anything that I care about, and that has worked out pretty well. But I am also in a very fortunate position where I don't have kids and I work in an industry that allows for relative autonomy.

This has been pretty stream-of-consciousness, and maybe 80% of this doesn’t even apply to your situation, so I’ll stop it here. Hope everything works out for you.