Fencing traces its roots to the development of swordsmanship for duels and self defense. Fencing is believed to have originated in Spain; some of the most significant books on fencing were written by Spanish fencers. Treatise on Arms was written by Diego de Valera between 1458 and 1471 and is one of the oldest surviving manuals on western fencing (in spite of the title, the book of Diego Valera was on heraldry, not about fencing) shortly before dueling came under official ban by the Catholic Monarchs. In conquest, the Spanish forces carried fencing around the world, particularly to southern Italy, one of the major areas of strife between both nations. Fencing was mentioned in the play The Merry Wives of Windsor written sometime prior to 1602.
The mechanics of modern fencing originated in the 18th century in an Italian school of fencing of the Renaissance, and under their influence, were improved by the French school of fencing. The Spanish school of fencing stagnated and was replaced by the Italian and French schools.
Development into a sport
The shift towards fencing as a sport rather than as military training happened from the mid-18th century, and was led by Domenico Angelo, who established a fencing academy, Angelo’s School of Arms, in Carlisle House, Soho, London in 1763. There, he taught the aristocracy the fashionable art of swordsmanship. His school was run by three generations of his family and dominated the art of European fencing for almost a century. 
1763 fencing print from Domenico Angelo’s instruction book. Angelo was instrumental in turning fencing into an athletic sport.
He established the essential rules of posture and footwork that still govern modern sport fencing, although his attacking and parrying methods were still much different from current practice. Although he intended to prepare his students for real combat, he was the first fencing master to emphasize the health and sporting benefits of fencing more than its use as a killing art, particularly in his influential book L’École des armes (The School of Fencing), published in 1763.
The first regularized fencing competition was held at the inaugural Grand Military Tournament and Assault at Arms in 1880, held at the Royal Agricultural Hall, in Islington in June. The Tournament featured a series of competitions between army officers and soldiers. Each bout was fought for five hits and the foils were pointed with black to aid the judges. The Amateur Gymnastic & Fencing Association drew up an official set of fencing regulations in 1896.
Fencing was part of the Olympics Games in the summer of 1896. Sabre events have been held at every Summer Olympics; foil events have been held at every Summer Olympics except 1908; épée events have been held at every Summer Olympics except in the summer of 1896 because of unknown reasons.
Starting with épée in 1933, side judges were replaced by the Laurent-Pagan electrical scoring apparatus, with an audible tone and a red or green light indicating when a touch landed. Foil was automated in 1956, sabre in 1988. The scoring box reduced the bias in judging, and permitted more accurate scoring of faster actions, lighter touches, and more touches to the back and flank than before.