When a company first develops a drug and releases it on the market, they will have a patent for the drug (usually lasting 20 years). A good example for a brand name is Aspirin from the German company Bayer.
The brand name is somewhat the equivalent of a car name, as an example Renault Megan.
After a patent expires, other companies can produce the same drug, under a different name.
A generic drug is a medication that has exactly the same active ingredient as the brand-name drug and yields the same therapeutic effect. It is the same in dosing, safety, strength, quality, the way it works, the way it is taken, and the way it should be used. Generic drugs do not need to contain the same inactive ingredients as the brand name product.
However, a generic drug can only be marketed after the brand-name drug's patent has expired, which may take up to 20 years after the patent holder’s drug is first filed with the U.S. Food and Drug Administration (FDA).
Generic drugs are usually much less expensive than brand name drugs once they reach the market.
In the case of Aspirin, Aspirin is still a registered trademark, but aspirin isn't. But because the drug is so famous, it is retailed by different companies under the name aspirin (lower-case a), which is not trademarked.
The active ingredient of Aspirin is acetylsalicylic acid. This is what a doctor should prescribe (but because aspirin is so famous, most people use that name instead of acetylsalicylic acid), and this is of interest to other doctors, pharmacists etc.. It basically tells you what the drug does, adhering to the nomenclature explained in this answer.
I've also encountered quite a few doctors, nurses or EMT's who said that there is sometimes confusion because brand names are so popular people refer to the active ingredient by the brand name (see acetylsalicylic acid).