When it comes to homebuying, one of the primary considerations buyers make is the quality of the schools.

Now RealtyTrac sifted through the data, and compiled a list of the markets with the best schools and the most affordable homes, and the best schools with the least affordable homes.

Here’s what they found: There were 489 zip codes with elementary schools where 2013 test scores were at least one-third higher than their respective state average and where the average price of a residential property required one-third or less of the median household income.

These zip codes also had a maximum unemployment rate of 5.9% in September.

Cities with the highest amount of affordable zip codes with good schools were led by Orlando, Fla., (9), Raleigh, N.C. (8), Phoenix, Ariz., (6), followed by five cities each with five affordable zip codes with good schools: Chandler, Ariz., Colorado Springs, Colo., Grand Rapids, Mich., Lexington, Ky., and Wilmington, N.C.

States with the most affordable zip codes with good schools were New York (105), North Carolina (66), Florida (62), Illinois (50), and Michigan (40).

The average test score for the best elementary schools in these 359 zip codes was 49% higher than their state average.

Click to enlarge

Then there’s the other side of the coin – markets with great schools but the least affordable homes.

There were 127 zip codes with elementary schools where 2013 test scores were at least one-third higher than the state average and where the average price of a residential property required two-thirds or more of the median household income. These zip codes also had a maximum unemployment rate of 5.9% in September.

Cities with the most unaffordable zip codes with good schools were New York, N.Y. (22), San Francisco, Calif., (8), Flushing, N.Y., (4), Newport Beach, Calif., (4) Oakland, Calif., (4),  San Jose, Calif., (4), and Portland, Ore., (3).

States with the most unaffordable zip codes with good schools were California (69) and New York (44). No other states had more than three unaffordable zip codes with good schools.

The average test score in these 91 zip codes was 60% higher than their state average.

Click to enlarge