Let me start by saying that I find both terms quite offensive. They are derisive terms, commonly seen on all of the D&D forums, that the author uses to describe a type of campaign that differs from her own. Both styles of play have merit. They both are also commonly misunderstood.
Railroading refers to a linear campaign, where the DM determines what adventures the group will have. Taken to extreme, the characters are seen to be forced along a predetermined path, where they fight a predetermined lineup of monsters, to reach a predetermined goal and where the players have little or no choice in the direction of the adventure. Certainly, there are some groups out there that play this way. However, that is not a typical linear campaign. At least not by my definition.
A great many DMs simply do not have the time or experience to create a well-defined campaign setting. Instead, they buy a module or create a single dungeon and tell the group that is where they will be adventuring that evening. Usually, there is a back-story that defines the reason for the group to be adventuring in that locale which often includes an overall goal. Granted, the players may be forced into a certain adventure but they may have full freedom once they get there as to how they will approach the adventure. They may choose to completely ignore the stated goal. They may even do something completely unexpected.
Time constraints are a very real factor. Many DMs just don’t have the time to prepare more than a single scenario at a time. I think it’s reasonable to have to make some allowances and give up some freedom of choice as a result.
Occasionally, a DM may have to introduce certain events to dissuade the party from following a course of action that would be harmful to the campaign or end in certain death for the party. This really isn’t any different from introducing plot hooks to entice the party into taking a desired action.
The party doesn’t operate in a vacuum. These types of outside influence make a great deal of sense. There are numerous NPCs, even deities, that have their own agendas and will try to influence the characters’ actions. This prodding is seen by some as “railroading”. This may be true if the characters truly have no choice in the matter but usually the party is free to do whatever they want. They may choose to accept someone’s plea for help, or completely ignore it if they want.
Outside influence is part of the game. As long as the players retain the ability to make their own choices, they aren’t being “railroaded” no matter how strong the coercion may be.
A sandbox game describes a campaign where players have total control over what they want to do. However, it is most commonly depicted as a totally random campaign, with no direction or story, where characters wander about having nothing but random encounters. They are usually portrayed as poorly run games by new DMs that don’t know any better.
Again, this may be true in some instances. However, I have yet to encounter a case like that.
My definition would be a fully developed world where the player has unlimited freedom of choice and that no matter what the player chooses to do, the DM is prepared to handle it. If the party chooses to wander about having nothing but random encounters, they should be free to do that. But there should also be enough rumors and existing character knowledge of the surrounding environs that the party can choose a more complex adventure as well. It could be said that this type of game has no direction or story. The same could be said about your own life. There is no predetermined story. The characters, like yourself, write their own story as they go and define their own direction.
Another misconception is that to create this type of fully developed world, the DM must map out and detail every tiny aspect of the world. That is totally unnecessary. The base of operations, main town or what have you, should be fully developed. Similarly, the immediate area must be detailed. Beyond that, vague ideas of what lies beyond the immediate area is all that is needed. Obviously, a handful of adventuring locales must be prepared and the DM must be ready to flesh out any area the characters choose to explore on the spur of the moment. Over time, more and more areas will become detailed and the world as a whole will develop more depth. But initially, a basic outline will suffice.
This type of campaign, however, does require tremendously more work than simply running a module, as well as requiring detailed knowledge of a variety of subjects.