Skip to content
mentua.org

Matching Markets and the Gale-Shapley Algorithm, Explained

Line drawing of three applicants linked by solid arrows to three schools, with dotted lines from the lower two applicants to the school above them, the middle school filledLine drawing of three applicants linked by solid arrows to three schools, with dotted lines from the lower two applicants to the school above them, the middle school filled

5 min read≈ 1,200 words3 questions · up to 3 points

What this is about

Every year, tens of thousands of new doctors in the United States learn on the same day where they will train, and no prices or bids decide it. You learn the rule behind that decision, how to run it by hand with three students and three schools, and why it matters so much which side gets to apply.

In a nutshell· skip ahead

A matching market is a market where both sides choose, such as jobs or school places, so prices cannot decide who gets what. The Gale-Shapley algorithm, also called deferred acceptance, solves this. Applicants apply in their order of preference, and each school holds its best applicant and rejects the rest, until nobody is rejected. The result is always stable.

In March 2026, more than 48,000 medical graduates in the United States learned on the same day which hospital, if any, would train them. Nobody had bid for a place. A computer program had read every graduate’s ranking of hospitals and every hospital’s ranking of graduates and produced one answer. Why do both sides accept it, and could the same lists have produced a different one?

What is a matching market?

A matching market is a market in which both sides choose, so you cannot just buy what you want, because you also have to be chosen. Jobs, school places and training posts for doctors all work like this. Since prices do not settle who gets what, the rules of the process do. The best-known set of rules is the Gale-Shapley algorithm, also called deferred acceptance, which the mathematicians David Gale and Lloyd Shapley published in 1962.

The algorithm aims for a stable matching: there is no applicant and school who are not matched with each other but would both prefer each other to the partners they got. Such a pair has every reason to make a deal outside the system, and a system that people leave soon stops working.

Deferred acceptance runs in rounds, with one side applying and the other only answering. Each student applies to the first school on their list, and each school holds its best applicant and rejects the rest. Rejected students apply to their next choice, and each school again keeps only the best of its new applicants and the one it holds. Holding is not accepting, because a held student can still be dropped. When nobody is rejected any more, the held places become final.

How does deferred acceptance work with three students and three schools?

Take three students, Maya, Leo and Zoe, and three schools, Hill, Lake and Park, each with one seat. Their rankings are:

First choice Second choice Third choice
Maya Hill Lake Park
Leo Hill Lake Park
Zoe Lake Park Hill
Hill school Zoe Maya Leo
Lake school Maya Leo Zoe
Park school Maya Leo Zoe

With the students applying, it takes three rounds.

  1. Maya and Leo apply to Hill, and Zoe applies to Lake. Hill prefers Maya, so it holds her and rejects Leo. Lake holds Zoe.
  2. Leo applies to Lake. Lake prefers Leo to Zoe, so it now holds Leo and drops Zoe.
  3. Zoe applies to Park, which holds her. Nobody is rejected any more, so the result is final: Maya at Hill, Leo at Lake and Zoe at Park.

Is this stable? Leo would rather be at Hill, but Hill prefers Maya, and Zoe would rather be at Lake, but Lake prefers Leo. No student and school prefer each other to their partners, so the matching is stable. Gale and Shapley proved that the algorithm always ends in a stable matching, whatever the rankings are.

Now we let the schools apply instead. Hill asks Zoe, while Lake and Park both ask Maya. Maya holds Lake, which she prefers, and turns Park down, so Park asks Leo. The result is Zoe at Hill, Maya at Lake and Leo at Park. This matching is stable too, but every school is better off and every student drops one place down their list.

What the Gale-Shapley algorithm teaches you

When both sides choose, the rules of the process can matter as much as anyone’s qualities. So ask two questions: who makes the offers, and is it safe to say what you really want?

When you apply for a school, a university place or a job through deferred acceptance with applicants applying, rank your options in your true order of preference. A long shot at the top cannot cost you a place further down, because a rejection only sends you on to your next choice. Outside such systems, the hold step is the part worth copying. An exploding offer, which forces you to say yes before you can compare, takes it away, so when you can, ask for time to hold an offer while you wait for others.

The most surprising fact is that practice came first. American hospitals set up a central clearinghouse for new doctors in the early 1950s, about ten years before Gale and Shapley’s paper. In 1984 the economist Alvin Roth showed that its procedure was essentially deferred acceptance with the hospitals applying, and he argued that stability was why it had lasted.

In 1997 the medical match switched to a design by Roth and Elliott Peranson in which the doctors apply. New York City adopted a version for its high schools in 2003, and the number of students placed at a school they had not listed fell from about 30,000 a year to about 3,000. Boston followed in 2005.

Where does deferred acceptance fall short?

Many people think the algorithm gives everyone the best possible result. It does not: it gives the best stable result to the side that applies and the worst to the side that answers. So choosing who applies means choosing who gets the advantage, though in the large medical market the difference proved small.

The second limit concerns honesty, which deferred acceptance makes safe only for the applying side. In 1982 Roth proved that no procedure that always produces a stable matching can make honest ranking the best strategy for everyone. When the schools apply in our example, Zoe ends up at Hill, her last choice. If she pretends she would never go to Hill and turns it down, Hill asks Maya, Maya leaves Lake, Lake asks Leo, Leo leaves Park, and Park asks Zoe. By lying, Zoe gets her second choice.

The third limit is couples. Doctor couples usually want two posts in the same city. Roth showed in 1984 that with couples, a stable matching may not exist at all. The medical match uses a modified algorithm that in practice almost always finds one, and 1,258 couples took part in 2026.

Finally, an algorithm only shares out what exists: if a city has too few good schools, deferred acceptance cannot create more.

Learn more

David Gale of Brown University and Lloyd Shapley of the RAND Corporation published “College Admissions and the Stability of Marriage” in 1962, using marriage as a simpler special case of college admissions. They recommended their proof to anyone who thinks mathematics is about numbers, since it is written in ordinary English and “one hardly needs to know how to count”. Shapley and Roth shared the Nobel Memorial Prize in Economic Sciences in 2012, but Gale had died in 2008, and the prize is not awarded after death.

The best next step is “Who Gets What and Why” by Alvin E. Roth: Summary and Review, because Roth tells the story of the medical match, New York’s schools and kidney exchange from the inside. For the contrast with a choice in which only one side decides, read What Is the Secretary Problem?, where you see options one at a time and nobody can turn you down.

Quiz

3 questions · up to 3 points

Open a question and pick one answer. Only your first answer counts: +1 if it is right, −1 if it is wrong.

  1. In deferred acceptance, what does a school do with the best application it has received so far?
    Show answer

    It holds the application but can still drop it for a better applicant later. Holding is not accepting. Only when nobody is rejected any more do the held applications become final, which is where the name deferred acceptance comes from.

  2. A city matches pupils to schools with deferred acceptance in which the pupils apply. Lena loves a popular school but thinks her chances there are low. What should she do?
    Show answer

    Rank the popular school first, because a rejection there cannot cost her a place further down her list. When the pupils apply, a rejection only sends Lena on to her next choice, with the same chances there as if she had ranked it first. Honest ranking is safe for the applying side.

  3. A friend says that deferred acceptance gives everyone the best result they could get. What is correct?
    Show answer

    It gives the side that applies its best stable result and the side that answers its worst. Gale and Shapley proved this in 1962. In the example, the same rankings gave every student a better school when the students applied than when the schools did.

The takeaway

The Gale-Shapley algorithm, or deferred acceptance, matches two sides that both choose: applicants apply in order of preference, and each school holds its best applicant until nobody is rejected. It always ends in a stable matching, where no applicant and school prefer each other to their partners, and it matches American doctors and New York pupils. It favors the side that applies, and only that side can rank honestly without risk. So when a system matches you, ask who applies and whether honest ranking is safe.

Key quotes

“any argument which is carried out with sufficient precision is mathematical”
David Gale and Lloyd S. Shapley, College Admissions and the Stability of Marriage, American Mathematical Monthly 69 (1962), p. 15

References

  1. College Admissions and the Stability of Marriage. David Gale and Lloyd S. Shapley, The American Mathematical Monthly, vol. 69, no. 1, pages 9-15, 1962

    The original paper: seven short pages that define stability, describe deferred acceptance and prove it always works, mostly in plain English.

  2. Stable matching: Theory, evidence, and practical design. NobelPrize.org, 2012

    The Nobel committee's popular explanation of the algorithm, the medical match, New York school choice and kidney exchange.

  3. Stable Allocations and the Practice of Market Design. Economic Sciences Prize Committee of the Royal Swedish Academy of Sciences, NobelPrize.org, 2012

    The scientific background, with the results on honest ranking, couples, and the redesign of the medical match and of the schools in New York and Boston.

  4. The Redesign of the Matching Market for American Physicians. Alvin E. Roth and Elliott Peranson, NBER Working Paper 6963 (American Economic Review, 1999), 1999

    How the medical match was rebuilt so that doctors apply and couples fit in, and why the set of stable matchings turned out to be small.

  5. 2026 Main Residency Match by the Numbers. National Resident Matching Program, 2026

    The current figures for the American medical match: positions, applicants and couples.

matching-marketsgale-shapley-algorithmdeferred-acceptancestable-matchingstable-marriage-problemmarket-designschool-choicemedical-residency-matchnrmpgame-theorydavid-galelloyd-shapleyalvin-rothnobel-prize-economicsstrategy-proofnessalgorithms

What Is the Secretary Problem?

How to pick the best option when you see them one at a time and cannot go back. The 37 percent rule, worked through with ten flats, and its limits.

7 min read≈ 1,630 words3 questions