How does the USDA grading system work?
A thorough introduction to the specific methods behind grading is found here.

USDA beef grading has two primary components: a "quality" grade and a "yield" grade.  Both are done for a whole carcass, so all cuts from that carcass will have the same declared grade.  Most American consumers only see the "quality" grade at retail stores.  More detail can be found at the links.  

In sum, "quality" grading for retail cuts -- usually Prime, Choice, and Select -- is ONLY a reflection of marbling (i.e., fat distributed through lean muscle), which tends to influence tenderness and flavor in fast-cooking methods.  Basically, you should use a quality grade to help determine a good steak or perhaps a prime rib roast.  That's where the rating system is most relevant for consumers.

Because "quality" is only based on marbling, different breeds of cattle and feeding regimens may result in incompatible "quality" estimates.  The most common example today is probably the rise in grass-fed and free-range cattle.  These tend to produce a much smaller amount of Prime graded carcasses, since they tend to be leaner overall than grain-fed cattle and/or those in confined feedlots.

(Note that studies have shown the vast majority of American consumers do not know what the rating system is about, with more than half thinking that high "quality" ratings correspond to leaner beef, when the opposite is true.)



Quality Grades

USDA beef "quality" grades only measure two things:


Marbling in the ribeye muscle at the cut surface between the 12th and 13th ribs.  (This is the traditional place where the carcass is separated between the "front quarter" and the "hind quarter".)
Apparent age at slaughter, based on bone and cartilage development and color/texture of lean meat.  Note that this is not based on actual chronological age, but rather the apparent physiological age, which might vary depending on growth conditions, feed, etc.  When there's a conflict between age estimated by bone development vs. lean meat color and texture, the bone development is generally given greater weight in determining age for grading.  (This age element is not of much relevance for retail grading, as will be discussed below.)


That's it.  Beef grading does not consider flavor, texture (except as a minor contribution toward determining age), cattle breed, living or slaughtering conditions, or any other factors that consumers might associate with "quality."  It also does not consider any individual parts or cuts of the carcass, which could vary in significant ways (e.g., in different cattle breeds or depending on exercise, feed, and other "lifestyle" elements for the cow).

Age grading is only relevant in determining whether the cow is less than or greater than 42 months of (physiological) age.  If less than 42 months of age, the carcass may be graded in one of the categories (Prime, Choice, Select, or Standard) which tend to be seen at retail sale.  Meat from those graded at more than 42 months of age rarely end up at retail markets (since they can only be graded Commercial, Utility, Cutter, or Canner grades, and mostly end up in processed products).  So age grading is basically irrelevant for the typical American consumer when choosing a retail cut.

Thus, the only thing a retail "quality" grade represents is marbling between the 12th and 13th ribs (which is roughly indicative of marbling through much of the beef).

For those retail cuts, the grading may fall into four categories:


Prime, which has "abundant" or "moderately abundant" marbling.  (Trivia note: cow carcasses cannot be rated Prime, only steers, bullocks, and heifers.  Also, bull beef grades are not directly comparable to others.)
Choice, which has "modest" amounts of marbling.
Select, which has a "slight" amount of marbling.  Note that Select beef must be age graded at less than 30 months, which may tend toward a slightly more tender product to make up for the decreased marbling.  Prime and Choice grades allow up to 42 months of age, with no difference in rating.
Standard, which has "traces" or no marbling at all.  Beef that would end up as Standard grade is usually not graded at all, but rather sold at retail as ungraded meat, often as a "store brand."  (It also allows up to 42 months of age.)


There is often more detail given in grading, such as a "Choice+" or "Choice-" to indicate more detail in marbling, but retail stores rarely present that information.

Sometimes Commercial grade beef appears at retail, which may have variable marbling, but the carcass is greater than 42 months of age.  When sold at retail (if at all), it will not generally be advertised with this grading, again perhaps appearing as a "store brand."  As mentioned above, older meat also has lower grades that basically never appear at retail.  Moreover, beef grading is voluntary, so retailers have no obligation to advertise grades.

It's also important to note that some retailers will use similar terminology that can appropriate these adjectives in a variety of ways to make the meat sound like it's a higher grade.  (The USDA officially approves of and even gives examples of this practice.)  For example, a store brand might label its products "Nation's Choice" or "Lean-Choice" (for leaner meat) or "Prime Rib of Beef," even if the actual meat is graded lower, such as Select grade.  Consumers should look for the official "USDA Shield" and grading symbol, which is the main way to determine whether the nomenclature actually refers to quality grading.



Yield Grades

Carcasses are also graded within the USDA system by their expected total yield of trimmed retail cuts, based mostly on amount of surface fat.  The system is numerical, from 1 to 5, with 1 having the most yield (and lowest amount of trimmable fat) and 5 having the least yield (most external fat).

Yield grades are mostly used among meat packers and retailers to get a sense of how much meat they can extract from each carcass.  Consumers very rarely see these grades.



History of USDA Grading

Details can be found here.

The USDA beef grading system was gradually developed in the early 1900s.  The modern system was basically adopted in 1926 and implemented in 1927.  Originally, the intention was to standardize grading across the nation.  One effect was to allow local and regional meat producers to compete with national packers -- by having a term like Prime or Choice to sell at retail, they could compete against the "house brands" of familiar national packers.  (Originally, Select grade was labeled as Good; this was changed in 1987 in response to consumer perception studies.  Various other alterations to the system over the years; see the link.)

The large national meat packers fought this grading system and developed their own internal grading systems to compete with the USDA, but these alternative systems disappeared within a few decades.  Nowadays, of course, large-scale meat packers are the norm in the US again.