It's okay to only have one path and it's okay to only have one correct way to follow that path. The path gains unwelcome rails when the player tries to leave it and can't. Railroading is when an adventure has a linear path that players struggle to stay on and the DM is obvious in contriving to force them to stay on it. Bad railroading happens when this bothers people.
The struggle to stay on the path may come from character motivations or lack thereof, from information about the path being poorly communicated or poorly understood, from there seeming to be other paths that seem to make more logical sense, or from there seeming to be other paths that are more fun or interesting. Contriving to force players on the path may take the form of the DM having attempts to deviate continuously fail in sometimes improbable ways, having NPCs swear up and down that they need to do X and improbably unwilling to consider doing Y or Z, giving agency to NPCs, outright making player character decisions for them, telling players every idea they have won't work, or all manner of other sins that break the sense of agency, break the verisimilitude, or otherwise take people out of the game.
Why did players struggle to stay on the path? It may be that the path was just too linear. It may be that the DM (or whoever created the module) failed to give sufficient motivation to get on or stay on the intended path. It may be that they failed to give sufficient information to do so. It may be that they simply didn't think of all manner of alternative solutions to things that the players do think of, either because nobody can think of everything or because the DM or module designer missed something obvious. Sometimes it can be an "unreasonable" player's fault. Maybe they just want to do random things, maybe they have a character who does not accommodate going on the adventure, maybe they don't pay any attention to what's going on and don't know what they are supposed to be doing. Maybe they are just a poor fit for that group or that DM.
In any case, struggling to stay on a linear path is going to happen to some degree or another a certain amount of the time. It becomes railroading if the DM decides they can not or are unwilling to accommodate the alternative path, fails to nudge players back onto the intended one discretely, and resorts to various means players find increasingly obvious and likely obnoxious to keep them on the planned path. Sometimes this may take the perfectly acceptable form of "sorry guys, this is the adventure I have prepped for today" or "this is how the written module goes and I'm not comfortable modifying it for the thing you want to do". This is a form of railroading, but not one reasonable players hold against their DM, especially if the DM was someone who half-willingly stepped up to the plate and/or has a busy life outside of D&D. Other times the DM may nudge players onto the intended path through gentler in-game incentives, disincentives, or just plot developments and the players may simply take the hint and be okay with it, or go along without ever knowing they were steered back onto the rails. No real harm here either; there may be rails but nobody had a quarrel over them.
The railroading problems happen when the DM has put the party on rails, the party tries to get off, and the DM can't just admit that they are railroading the party, tries to coerce them to stay on the rails through in-game methods, and does so in ways that seem unfair, illogical, break immersion, and so forth. A DM with sufficient improvisation talent could probably give players satisfactory reasons to stay on the intended path almost all the time, but they likely don't need to do so much of the time because they likely also have the skills to improvise out many of the alternative paths players may choose. A DM who has a good feel for the players and their characters could have designed the intended path to appeal to them and anticipated what alternative approaches they might need to plan for in advance, either to accommodate a different path of to disincentivize taking it. A DM who can't adapt to an alternative path at all and who did not anticipate obvious alternative decisions players might make, however, is also often a DM who is going to improvise poor methods for coercing people to stay on the path they want because they are likely someone who is inflexible, a poor improviser, and/or doesn't have a good feel for the players and their characters. Naturally the DMs most throughly in this camp are likely to commit all manner of other sins unrelated to putting the party on rails, giving railroading all manner of disreputable associations.