Many historians believe that Independence Day’s most explosive form of entertainment originated in China, which continues to produce and export more fireworks than any other country in the world. (Others trace their roots to the Middle East or India.) It is thought that, as early as 200 B.C., the Chinese had already stumbled upon a sort of natural firecracker: They would roast bamboo, which explodes with a bang when heated due to its hollow air pockets, in order to ward off evil spirits.

At some point between 600 and 900 A.D., Chinese alchemists—perhaps hoping to discover an elixir for immortality—mixed together saltpeter (potassium nitrate, then a common kitchen seasoning), charcoal, sulfur and other ingredients, unwittingly yielding an early form of gunpowder. The Chinese began stuffing the volatile substance into bamboo shoots that were then thrown into the fire to produce a loud blast. The first fireworks were born.

Soon, paper tubes came to replace the bamboo stalks, and the Chinese discovered that their fiery sticks could be used for more than just scaring away ghosts and celebrating special events. By the 10th century, they had developed crude bombs and begun attaching firecrackers to arrows that rained down on their adversaries during military engagements. Two hundred years later, they learned how to fire explosives into the air and guide them toward enemy targets, essentially building the first rockets. Used outside the field of battle, the same technology allowed fireworks masters to put on the first aerial displays.

In the 13th century, gunpowder samples and formulas began trickling into Europe and Arabia, transmitted by diplomats, explorers and Franciscan missionaries. Western scientists, metallurgists and military leaders threw themselves into making the substance even more potent and building powerful weapons such as cannons and muskets.

Meanwhile, the softer side of gunpowder—fireworks—became increasingly popular first to commemorate military victories and later to enhance public celebrations and religious ceremonies. In medieval England, fireworks experts were known as firemasters. Their assistants, called “green men” because they wore caps of leaves to protect their heads from sparks, doubled as jesters, entertaining the crowd with jokes as they prepared the displays. It was a dangerous profession at the time, with many green men dying or suffering injuries when detonations went awry.

READ MORE: Why We Celebrate the Fourth of July With Fireworks

By the time of the Renaissance, pyrotechnic schools were training fireworks artists across Europe, particularly in Italy, which became famous for its elaborate and colorful displays. It was the Italians who in the 1830s became the first to incorporate trace amounts of metals and other additives, creating the bright, multihued sparks and sunbursts seen in contemporary fireworks shows. Earlier displays only featured booming sounds, orange flashes and faint golden traces of light.

Fireworks gained an especially strong following among European rulers, who used them to enchant their subjects and illuminate their castles on important occasions. In England, the earliest recorded display took place on Henry VII’s wedding day in 1486. In 1685, James II’s royal firemaster achieved such a dazzling presentation for the king’s coronation that he received a knighthood. French kings regularly put on spectacular displays at Versailles and other palaces, while Czar Peter the Great of Russia arranged a five-hour pyrotechnic extravaganza to mark the birth of his son.

Europeans brought their knowledge and appreciation of fireworks to the New World. According to legend, Captain John Smith set off the first display in Jamestown in 1608. Records show that some American colonists may have gotten a little carried away: A spate of firecracker-related pranks in Rhode Island became such a public nuisance that officials banned the “mischievous use of pyrotechnics” in 1731.

On July 3, 1776, the day before the Continental Congress adopted the Declaration of Independence, John Adams wrote a letter to his wife in which he presaged the role of fireworks in Fourth of July celebrations. “The day will be most memorable in the history of America,” he predicted. “I am apt to believe that it will be celebrated by succeeding generations as the great anniversary festival. It ought to be solemnized with pomp and parade…bonfires and illuminations [a term for fireworks]…from one end of this continent to the other, from this time forward forevermore.”

The following year, fireworks displays commemorated the fledgling country’s first anniversary, just as they have each subsequent one. They also light up the skies to mark other events of national importance, including presidential inaugurations going all the way back to George Washington’s, and holidays such as New Year’s Eve.

In the 1890s, rampant detonation of fireworks, particularly by unskilled ruffians, drove concerned citizens to form the Society for the Suppression of Unnecessary Noise, which lobbied for restrictions. Today, most states regulate how and where fireworks may be used, as well as the types of explosives consumers may buy. These laws notwithstanding, nearly 9,000 Americans were hurt by fireworks in 2009, according to the Consumer Product Safety Commission, with a disproportionate number of injuries occurring in July. Experts recommend precautions such as only detonating fireworks outside, obeying local ordinances, keeping water handy in case of a fire, preventing children from handling explosives and, most of all, using common sense. Visit the website of the National Council on Fireworks Safety for more tips.

Where can you catch a glimpse of the flashiest displays this Fourth of July? Some of the most famous shows take place over the Hudson River in New York City, along Boston’s Charles River, at the National Mall in Washington and in front of the Philadelphia Museum of Art.