A catapult is a war machine meant to fling some sort of projectile. Though the term may be applied to modern weapons that hurl their payloads, it is usually understood to refer to a specific type of metal and wooden machine popular during the Middle Ages in Europe.
The earliest type of catapult was essentially a large crossbow, shooting a projectile straight at an enemy or at a slight arc. The Greeks were responsible for the first of these, the gastraphetes and the oxybeles, the former being a large crossbow braced against the belly, and the latter being a tripod-mounted crossbow. Alexander the Great made good use of this primitive type of catapult, using them to break sieges, such as the famous Siege of Tyre. The Romans took the Greek model and transformed it into their own, more sophisticated ballista, which in time became one of the integral weapons of the Roman Empire and is considered by many to be the most sophisticated weapon of war made at any point before the Industrial Revolution.
The first type of catapult to resemble that which most people envision when they hear the word is properly known as an onager. An onager catapult consists of a sturdy wooden frame and an arm holding a sling that can be winched down to store up energy. This energy, when released, launches the arm up at an arc, throwing whatever is in the sling great distances. Onagers were very popular in sieges, used for launching enormous stones to do damage on impact. Alternatively, missiles could be coated with some sort of flammable material and launched as burning spheres towards their target.
A different sort of catapult, relying on counterweight rather than winching a rope, is the trebuchet. This type of catapult is thought to have originated in China sometime in the 5th century BCE, though it didn’t reach Europe for another thousand years. A trebuchet catapult basically consists of a huge counterweight attached to the short side of a long arm and a sling attached to the long side. The short arm is then raised into the air, at which point the trebuchet is cocked and need only be released for gravity to take effect and launch whatever payload is in the sling.
The trebuchet is much more accurate than the onager or most other types of siege weaponry, and as a result was preferred for destroying specific sections of a wall when laying siege to a fort or castle. It was also used during Middle Ages warfare to hurl the dead bodies of plague-infected people over walls in an attempt to infect those within.