Like
@jgsugden I use the guidelines from the book. At the lower end of the scale, people often don't need to roll.
The trick, of course, is to figure out the difficulty and that just depends on the fiction. Sneaking past a drunken, half asleep guard? The rogue doesn't need to roll but sadly the fighter in heavy armor and a bad dex does because even at 20th level they'll still have a decent chance to fail that DC 5 check because they likely still have a -1 penalty to the check with disadvantage.
We can give all sorts of descriptions about how we set DC, and I don't disagree with any of the posts above. But describing why something is a specific DC, while useful, kind of misses the point. We only have DCs for things that are not automatic. So when we assign DCs it's because we want some dramatic tension, we want a chance of failure. Failure can mean many things including just not being able to open that lock quickly or it could mean something bad happens.
But going back to that "sneaking past a guard" example, I either base it on what I envision for the current setting or I set it based on the capabilities of the PCs because I want it to be a challenge. For examples of the setting determining the DC, imagine if it's late at night and the guards aren't very good, it will be the DC 5. On the other hand if it's the imperial palace and the guards are the best of the best but still human then it will be DC 20. If the guards are supernatural and you're trying to sneak into a archdevil's palace it will be DC 30.
Another example would be checks to know something about my world. Then I base it on how common something should be. Religious symbols of well known but not locally worshipped gods may be a 5, so if you're trained in religion you'll likely know. That monster that hasn't appeared in over a thousand years and even then was only infrequently seen? DC 30.
Suppose on the other hand that I'm doing something as a challenge to the PCs. This happens in the planning stages for a session when I haven't already thought about or previously established the location and the types of guards they have. At that point I'm thinking how to make fun and interesting encounters. So yeah, I'm going to take into consideration the capabilities of the PCs just like I take into consideration the CR of possible monsters they may encounter. Something the whole group needs to succeed at? Likely a pretty low check, since most people aren't going to be trained. Slightly higher if I allow different training or assistance. But if it could be done by just the rogue? How high do I need to make the DC to ensure that there's a risk?
So I think it's generally a good idea to have at least a general idea of what your players PCs are capable of so you don't have them roll for things that will be automatic or impossible.