The Handshake Problem: Creating a Mathematical Solution

Updated on April 18, 2020
David3142 profile image

I am a former maths teacher and owner of Doingmaths. I love writing about maths, its applications and fun mathematical facts.

A Group Handshake
A Group Handshake | Source

The Handshake Problem

The handshake problem is very simple to explain. Basically, if you have a room full of people, how many handshakes are needed for each person to have shaken everybody else's hand exactly once?

For small groups, the solution is quite simple and can be counted fairly quickly, but what about for 20 people? or 50? or 1000? In this article, we will look at how to work out the answers to these questions methodically and create a formula that can be used for any number of people.

Small Groups

Let's start by looking at solutions for small groups of people.

For a group of 2 people, the answer is obvious: only 1 handshake is needed.

For a group of 3 people, person 1 will shake the hands of person 2 and person 3. This just leaves person 2 and person 3 to shake hands with each, other for a total of 3 handshakes.

For groups larger than 3, we will require a methodical way of counting to ensure we don't miss out or repeat any handshakes, but the math is still fairly simple.

Groups of Four People

Let's suppose we have 4 people in a room, whom we shall call A, B, C and D. We can split this into separate steps to make counting easier.

  • Person A shakes hands with each of the other people in turn—3 handshakes.
  • Person B has now shaken hands with A, still needs to shake hands with C and D—2 more handshakes.
  • Person C has now shaken hands with A and B, but still needs to shake D's hand—1 more handshake.
  • Person D has now shaken hands with everybody.

Our total number of handshakes is therefore 3 + 2 + 1 = 6.

Larger Groups

If you look closely at our calculation for the group of four, you can see a pattern that we can use to continue to work out the number of handshakes needed for different sized groups. Suppose we have n people in a room.

  • The first person shakes hands with everybody in the room except for himself. His total number of handshakes is therefore 1 lower than the total number of people.
  • The second person has now shaken hands with the first person, but still needs to shake hands with everybody else. The number of people left is therefore 2 lower than the total number of people in the room.
  • The third person has now shaken hands with the first and second people. That means the remaining number of handshakes for him is 3 lower than the total number of people in the room.
  • This continues with each person having one less handshake to make until we get to the penultimate person, who only has to shake hands with the last person.

Using this logic we get the numbers of handshakes shown in the table below.

The Number of Handshakes Required for Different Sized Groups

Number of People in the Room
Number of Handshakes Required

Creating a Formula for the Handshake Problem

Our method so far is great for fairly small groupings, but it is still going to take a while for larger groups. For this reason, we're going to create an algebraic formula to instantly calculate the number of handshakes required for any size group.

Suppose you have n people in a room. Using our logic from above:

  • Person 1 shakes n - 1 hands
  • Person 2 shakes n - 2 hands
  • Person 3 shakes n - 3 hands
  • and so on until you get to the penultimate person shaking the 1 remaining hand.

This gives us the following formula:

Number of handshakes for a group of n people = (n - 1) + (n - 2) + (n - 3) + ... + 2 + 1.

This is still a little bit long, but there is a quick and convenient way to simplify it. Consider what happens if we add the first and last terms together: (n - 1) + 1 = n.

If we do the same thing for the second and second to last terms we get: (n - 2) + 2 = n.

In fact, if we do this all the way down we get n each time. There are obviously n - 1 terms in our original series as we are adding the numbers from 1 to n - 1. Therefore, by adding the terms as above, we get n lots of n - 1. We've effectively added our entire sequence to itself here, so to get back to the sum we require we need to halve this answer. This gives us a formula of:

Number of handshakes for a group of n people = n × (n - 1) / 2.

We can now use this formula to calculate the results for much larger groups.

The Formula

For a group of n people:

Number of handshakes = n × (n - 1) / 2.

Number of People in Room
Number of Handshakes Required
499 500

An Interesting Aside: Triangular Numbers

If you look at the number of handshakes required for each group you can see that each time the group size increases by one, the increase in handshakes is one more than the previous increase had been. i.e.

  • 2 people = 1
  • 3 people = 1 + 2
  • 4 people = 1 + 2 + 3
  • 5 people = 1 + 2 + 3 + 4, and so on.

The list of numbers created by this method, 1, 3, 6, 10, 15, 21, ... is known as the "triangular numbers." If we use the notation Tn to describe the nth triangular number, then for a group of n people, the number of handshakes required will always be Tn-1.

© 2020 David


    0 of 8192 characters used
    Post Comment

    No comments yet.


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
    ClickscoThis is a data management platform studying reader behavior (Privacy Policy)