One of the first pieces of advice I heard when I began my time as a DM was "don't say no to your players, just let them try." And while in essence this is good advice, it ends up being too broad of a statement. Sometimes you should say no to your players, but that almost never means actually uttering the word "no". Here are some of the ways you can say "no" without making anyone angry or derailing great ideas.
Also, as a disclaimer, this refers to in-game actions. This is not a post about figuring out races/classes in a session zero, about talking to players about behaviour at the table or giving advice on dealing with issues with players themselves. This is about actions within a session.
The "Yes And..."
One of the most fundamental tools in any improvisational form is the "yes and..." which essentially allows you to take something that your players have said, that's the "yes" part, and then modify it to fit your purposes as well as theirs. In DnD this often looks a little bit more like "yes, but..." but the concept still applies. Here's an example.
The DM has set up an ambush with a group of orcs, but as they approached the party gets lucky with a high perception roll.
Player: "Okay our high perception let us hear those orcs that are following. Can I get to the top of that tree to see how long we have before they get here?
DM: "Yes, but if you can see them they can see you, and once they know you've spotted them they may change their tactics."
Another example. A player has just defeated a boss and wants to kill it in a super cool way, but you need that boss to deliver information necessary for the plot to keep moving.
Player: "I slide right under him and pop up on his backside, then with my two swords crossed I whisper 'don't lose your head over it' and scissor my two swords to pop his head right off!"
DM: "Yes! Excellent, and as the head comes off and lands at your feet the body turns, and a voice speaks as if the head were still upon the shoulders. 'You have slain my vassal and gained my ire. Now I shall have to kill you myself,' it says before the body slumps down next to the head."
These are example of allowing a player to do exactly what they want, but also give them an idea of consequences or deliver what needs to be said anyways. In the first example, another option is to simply let them climb a tree, and then have them witness the consequences. This leads us nicely into the second way of saying "no".
Let the World Say No
With low-consequence stuff it's generally okay to let the player try. If there's damage or gold involved often things are a little more tricky, but if it's not game breaking then a quick narration that shows that what they thought was going to happen won't happen generally suffices.
Player: "I want to parkour up to the highest tower of the castle and sneak inside! 19 plus five on acrobatics!"
DM: "Great, unfortunately there are no structures that reach up as high as the tallest tower and it is a sheer tower with no handholds. You are able to quickly and easily, with a sick looking series of flips and careful footwork, get up to the roof of the nearest tall building, but you're still about 50 feet below the top of the tower and about 20 feet away."
I was once in a game where a player wanted to fashion a glider out of a loincloth, and the DM let him roll for it. Now here's a piece of advice. If you, DM, don't want something to work, explicitly don't want it to even have a chance of working, do not let the player roll. It is always the rolls when you think "okay this is insane but I should let them try, so they're going to need a natural 20 to even make it plausible" when the player will inevitably roll a natural 20. Which is exactly what happened. Now I think up to this point everything is fine, since the DM has allowed the player to try something that's fun and cool, and thus the player has been rewarded for thinking outside the box. The problems begin after this point, and fault lies with both player and DM in this scenario. The player launches himself off a cliff with said glider, hoping to fly over to the next mountain (this would constitute being a little bit game breaking). The player should not have done this. He left his whole party behind, didn't test the glider, and tried to cut out a decent portion of the module by simply flying over it. The DM, to be fair, probably should not have allowed him to get right over the deepest part of the valley before the glider started to fail, which ended up casting the PC down at the worst possible time. He took maximum fall damage, but, because dice hate DMs, he didn't die. So then the DM ruled that he was quadriplegic from the fall. Now the DM is clearly unhappy because he's had a player partially break his game, and he's overreacted by forcing the player to still exist (rather than swap out a new character) without being able to actually move. So let's rewind and explore some ways we could have switched this scenario.
One way is to show the player that a loincloth is not enough material to make a functionable glider with. This is a little less fun, but it eliminates the threat of exactly what happened from happening. DM goes "you judge the size of the loincloth won't be enough to actually bear any weight. You can relatively easily create what looks like a glider, but even cursory tests show that it's pretty much just a toy." The advantage of this is the player won't try to use it, but it might still be used later for a completely different purpose. Maybe there's a gnome NPC they can sell it to, or use it as a distraction by throwing it a different direction in an upcoming fight.
Another way would be to let the player roll, and actually have the glider function depending on that roll, but only up to a certain point. So in this case, with a natural 20, the glider might actually be able to bear weight, but becomes unstable and loses height super quickly. So if the player launches off of a cliff he quickly loses height, realizes it's usable but only for 20-30 feet, doesn't break his spine, but is still rewarded for thinking outside the box. In this case, the DM isn't saying, "no you can't make a usable glider," they're saying, "no you can't fly from one mountain to another without the use of spells or wings." See how much more reasonable the second negation is?
Impossible vs Improbable
The reason anyone ever gives the advice to "never say no" or "let them try" is because DnD is built around trying to do stuff unusual. That's a broad statement, but in essence, if you had a limited number of actions then it would be more fun to just play a videogame. The ability to only be limited by your imagination is what makes it fun, but (you knew there was going to be a but right?) that doesn't make anything possible. The game still has rules, and those rules should, for the most part, be adhered to. But those rules allow for lots of creativity. The times when you say "no", and here I'm essentially referring to an outright "no", are when a player wants to break the rules for their own purposes.
Player: "I want to jump across this canyon."
DM: "The canyon is 100 feet across."
Player: "I rolled a Nat 20 plus 8 Athletics."
DM: "Here are your options, as a generous god. You pretend you didn't roll before I asked you to and recognize that this canyon is physically impossible to jump across unaided; or you make the most spectacular leap you have ever accomplished, travelling a very impressive 40 feet before plummeting into the 100 foot wide canyon."
This is a bit of a silly example, and even maybe a bad one if you think it would be more fun to let that player try to leap a canyon, but what the player is essentially trying to do is break (or severely bend) the rules to allow them to fly despite the fact that they chose a race/class which cannot fly. Because leaping 100 feet is insane. But, if that same player puts in a little bit of thought, and comes up with a cool way to bridge that gap, be it by using a physical bridge to get part of the way, a pole to vault to increase distance, or by thinking of ways their party members can help them, then maybe having them roll an actually accomplishable check and get themselves across that distance is reasonable. Some things in DnD are impossible, but very few of those impossible things can't be turned into improbable things by using teamwork or creativity. Allowing your players to circumnavigate that fact takes away what makes it special. And just because sometimes players do unexpected things doesn't mean they're necessarily trying to break the game. They're having fun and thinking outside the box, and adapting to stuff is fun. I believe that applies to both DM and player alike. If a party has a strong Perception, let them spot the ambush and then adapt to it, while you adapt your ambush plan in kind. If your player wants to leave his party behind and glide to the next mountain over, let him; but uh oh, there's a Yeti there. A player wants to jump a hundred foot chasm without any tools or magic? Well, they can tell before doing so that even with the greatest leap ever achieved by a mortal, they would not be able to. And of course, if that player pushes the issue, you let them "try".