Take 10 mortgages, each with a balance of $200,000. Put them together into a $2 million MBS. Turn the MBS into 3 tranches, a senior tranche that gets paid the first $1 million, a mezzanine tranche that gets paid the next $500,000, and a Z-tranche (often known in the business as toxic waste). So long as less than half of those 10 mortgages go bad, the senior tranche collects everything. The mezzanine tranche then starts to collect, and is OK so long as at least 8 of the 10 mortgages are good. The Z tranche is risky as hell.
To get a AAA rating on a mezzanine tranche is almost impossible, and on a Z tranche literally impossible. To get a AAA on a senior tranche the rating agencies look at how much of the MBS has been subordinated (50% is VERY good, 10% is not so good), on the loan-to-value distributions and credit scores of the underlying loans, and on the insurance. Insurance is of 2 types – the standard private mortage insurance that comes from PMI, GE, Radian, etc., and pool insurance that comes from bond market isurers. A pool of all 80% or less LTV fixed rate mortgages with FICO scores over 680 may require very little subordination to get a AAA (it will require some), a pool of 95% subprimes with option arms may require 50% subordination and pool insurance to get a AAA.