Weight is measured by how much gravity acts on you, which is why you would weigh less on the Moon, which has less gravity than Earth, than you would at home. So scientists talk about mass rather than weight, as mass is the same no matter where you are.
To understand how we are able to calculate the mass of a planet, you have to first start with the principle called the Law of Universal Gravitation, published in 1687 by Sir Isaac Newton. Newton’s work tells us to look at how a planet affects the things around it. First, find a planet with a handy second object nearby like a moon. Second, measure the distance from the moon to the planet. Third, time one complete orbit. This gives you a moon’s speed, and the faster the moon is going the bigger the planet must be.
This only allows you to compare the relative masses of planets. To find out the actual masses of planets we had to wait for Lord Henry Cavendish’s experiment in 1797. He set up an experiment with two 150kg lead balls representing planets, and two smaller spheres, representing moons, and he measured the gravitational pull between them. Cavendish’s experiment led us to the missing piece of Newton’s puzzle, which was the value of G – the number that relates the gravitational force between two bodies to their masses and distance apart. By putting the value of G into Newton’s equation Cavendish calculated Earth’s mass to be six billion trillion tonnes, which is within 1% of our best guess today.