A public execution is a form of capital punishment which "members of the general public may voluntarily attend."  This definition excludes the presence of a small number of witnesses randomly selected to assure executive accountability.  The purpose of such displays has historically been to deter individuals from defying laws or authorities. Attendance at such events was historically encouraged and sometimes even mandatory.
While today most countries regard public executions with distaste, in the past they were preferred to executions behind closed doors because of their capacity for deterrence. They also allowed the convicted the opportunity to make a final speech, gave the state the chance to display its power in front of those who fell under its jurisdiction, and granted the public what was considered to be a great spectacle.  Public executions also permitted the state to project its superiority over political opponents.  Thus, when Charles I of England was beheaded, the reduced height of the block meant that he could not assume the normal kneeling pose, but was forced to lie in a face-down position considered to be especially humiliating. 
Executions had been condemned by 18th Century Enlightenment thinkers like Montesquieu and politicians like Cesare Beccaria.  In Europe and in the northern U.S., the 19th and early 20th centuries saw a shift away from the spectacle of public capital punishment and toward private executions and the deprivation of liberty. 
1801 saw the last public execution at Tyburn Hill, after which all executions in York took place within the walls of York Castle (but still publicly) so that "the entrance to the town should not be annoyed by dragging criminals through the streets."  In London, those sentenced to death at the Old Bailey would remain at Newgate Prison and wait for their sentences to be carried out in the street. As at Tyburn, the crowds who would come to watch continued to be large and unruly. The last public execution in Great Britain occurred in 1868,  after which capital punishment was carried out in the privacy of prisons.
French authorities continued public executions up until 1939.  Executions were made private after a secret film of serial killer Eugen Weidmann's death by guillotine emerged and scandalized the process. Disturbing reports emerged of spectators soaking up Weidmann's blood in rags for souvenirs, and in response President Albert Lebrun banned public executions in France for "promoting baser instincts of human nature." 
The last public execution in the United States occurred in 1936.  As in Europe, the practice of execution was moved to the privacy of chambers. Viewing remains available for those related to the person being executed, victims' families, and sometimes reporters.
Frances Larson wrote in her 2014 book Severed: A History of Heads Lost and Heads Found:
"For as long as there were public executions, there were crowds to see them. In London in the early 19th century, there might have been 5,000 to watch a standard hanging, but crowds of up to 100,000 came to see a famous felon killed. The numbers hardly changed over the years. An estimated 20,000 watched Rainey Bethea hang in 1936, in what turned out to be the last public execution in the U.S." 
According to Amnesty International, in 2012 "public executions were known to have been carried out in Iran, North Korea, Saudi Arabia and Somalia."  Amnesty International does not include Syria, Afghanistan, and Yemen in their list of public execution countries, but there have been reports of public executions carried out there by state and non-state actors, such as ISIS.    Executions which can be classified as public were also carried out in the U.S. states of Florida and Utah as of 1992. 
- Hood, Roger. "Capital punishment". Encyclopedia Britannica. Encyclopedia Britannica, Inc. Retrieved 3 October 2018.
- Blum, Steven A. (Winter 1992). "Public Executions: Understand the "Cruel and Unusual Punishments" Clause" (PDF). Hastings Constitutional Law Quarterly. 19 (2): 415. Archived from the original (PDF) on 2014-03-26.
- Cawthorne, Nigel (2006). Public Executions: From Ancient Rome to the Present Day. pp. 6–7. ISBN 978-0-7858-2119-9.
- "Punishment – The Enlightenment". science.jrank.org. Retrieved 2020-04-13.
- William J. Chambliss (2011). Corrections. SAGE Publications. pp. 4–5. ISBN 978-1452266435.
- "Executions in York: History of York". www.historyofyork.org.uk. Retrieved 2020-04-13.
- Steiker, Carol S.; Steiker, Jordan M. (2019). Comparative Capital Punishment. Edward Elgar Publishing. p. 167. ISBN 978-1-78643-325-1.
- Larson, Frances (November 2014). "Very Short Book Excerpt: The Allure of Execution". The Atlantic (This passage was adapted from the book 'Severed: A History of Heads Lost and Heads Found.'). p. 27.
- Rogers, Simon; Chalabi, Mona (2013-12-13). "Death penalty statistics, country by country". The Guardian. Retrieved 2015-12-13.
- "ISIS extremist reportedly kills his mother in public execution in Syria". Fox News. 2016-01-08. Retrieved 2016-05-30.
- CNN Library (3 September 2018). "ISIS Fast Facts". Cable News Network. Turner Broadcasting System, Inc. Retrieved 9 October 2018.
- "Video: Taliban shoot woman 9 times in public execution as men cheer". CNN. 2012-07-09. Retrieved 2016-05-30.