Legendaries are random drops. This means they can be better or worse than Magic or Rare items. The classification of items (into Magic, Rare, or Legendary) is based on the number of stats that they grant. For example, armor that has Strength, Dexterity, Gold Find, and Magic Find would be classified as Magic since it has four stats. If it also had Intelligence on it then it would have five stats and would be classified as Rare. I don't remember the number of stats for each level of classification, however, this is essentially how things are broken down into different rarity groups.
As previously mentioned, there are also craftable items that are categorized as legendaries. To craft these you need to get a pattern to drop and then...