Everything (even us) is made of atoms. At first, people thought that every different thing was made of a different type of atom. Later on, they realised that most things are a few types of atoms joined together in different ways. By about 1800, scientists had discovered about 40 elements (or different types of atom), and knew some of their properties. Then scientists started looking for patterns because that's what scientists do.
The first scientist to get anywhere with this problem was Johann Wolfgang Döbernier. In 1829, he noticed that the known elements mostly fitted into groups of three. The groups of three had similar properties, and each group of three had a light element, a heavy element and one with middleweight. Döbernier called his groups of three Triads (tri means three- like in triangle). For example, lithium, sodium and potassium were a triad of metals which reacted violently with water.
The next scientist in this story was John Newlands. In 1865, he wrote about a Law of Octaves (oct means eight- like in octopus). He took the elements known at the time and ordered them from lightest to heaviest. Some of the time, similar elements appeared every eighth position. This picture shows how that worked; the elements are sorted into order from light to heavy, and similar elements have been highlighted in bright colours.
Then came the key person in this story- Russian scientist Dimitri Mendeleev. He had two ideas which might seem obvious now but were revolutionary at the time.
First, there might be elements which exist but haven't been discovered yet. So leave gaps if it helps make the patterns work better.
Second, if the patterns (like the octaves) work better if pairs of elements are swapped around, then swap them.
The really impressive thing about Mendeleev's idea for the Periodic Table was that the gaps in the table were predictions of new elements to discover. The patterns in the table helped Mendeleev to predict what these elements would be like. After the Periodic Table was published, scientists looked for the missing elements. They all appeared and had the properties which Mendeleev had predicted.
In 1913 a British chemist, Henry Moseley, realised that it would be better to use an atomic number rather than mass, so he put the final touch on the Periodic Table. This resolved some issues that surfaced from Mendeleev's work.
The Periodic Table, as we know it today, is shown below. The different colours show elements with similar characteristics. They sit in columns; these are the triads of Döbernier (except the groups have more than three in them now), and repeat as Newland's octaves (for the first few rows, anyway). The crucial ideas to make the Periodic Table work came from Mendeleev.