The earliest known settlement on the present site of Kraków was established on Wawel Hill, and dates back to the 4th century. Legend attributes the town's establishment to the mythical ruler Krakus, who built it above a cave occupied by a ravenous dragon, Smok Wawelski. Many knights unsuccessfully attempted to oust the dragon by force, but instead, Krakus fed it a poisoned lamb, which killed the dragon. The city was free to flourish. Dragon bones, most likely that of mammoth, are displayed at the entrance of the Wawel Cathedral. Before the Polish state had been formed, Kraków was the capital of the tribe of Vistulans, subjugated for a short period by Great Moravia. After Great Moravia was destroyed by the Hungarians, Kraków became part of the kingdom of Bohemia. The first appearance of the city's name in historical records dates back to 966, when a Sephardi Jewish traveller, Abraham ben Jacob, described Kraków as a notable commercial centre under the rule of the then duke of Bohemia; and mentioned the Baptism of Prince Mieszko I as the first historical ruler of Poland. Mieszko took Kraków from Bohemians and incorporated it into the holdings of the Piast dynasty towards the end of his reign.
By the end of the 10th century, the city was a leading center of trade. Brick buildings were being constructed, including the Royal Wawel Castle with St. Felix and Adaukt Rotunda, Romanesque churches, a cathedral, and a basilica. In 1038, Kraków became the seat of the Polish government. In 1079 on a hillock in nearby Skałka, the Bishop of Kraków, Saint Stanislaus of Szczepanów, was slain by the order of the Polish king Bolesław II the Generous. In 1138 according to the Testament of Bolesław III Krzywousty Kraków was named a Seniorate Province, meant to be ruled by the rotating head of the royal family; however, the seniorate system soon collapsed, and a century-long struggle between Bolesław's progenies followed. The fragmentation of Poland lasted until 1320.
The city was almost entirely destroyed during the Mongol invasion of Poland in 1241, after the Polish attempt to repulse the invaders had been crushed in the Battle of Chmielnik. Kraków was rebuilt in 1257, in a form which was practically unaltered, and received self-government city rights from the king based on the Magdeburg Law. In 1259, the city was again ravaged by the Mongols, 18 years after the first raid. A third attack, though unsuccessful, followed in 1287. The year 1311 saw the Rebellion of wójt Albert against Polish King Władysław I. It involved mostly German-speaking citizens of Kraków who, as a result, abandoned their political ambitions. However, the rebellion cost Poland the city of Gdańsk (Danzig), which was taken over by the Teutonic Order in 1309.
The medieval Kraków was surrounded by a 1.9 mile (3 km) defensive wall complete with 46 towers and seven main entrances leading through them (see St. Florian's Gate and Kraków Barbican). The fortifications were erected over the course of two centuries. The town defensive system appeared in Kraków after the city's location, i.e. in the second half of the 13th century (1257). This was when the construction of a uniform fortification line was commenced, but it seems the project could not be completed. Afterwards the walls, however, were extended and reinforced (a permit from Leszek Biały to encircle the city with high defensive walls was granted in 1285). Kraków rose to new prominence in 1364, when Casimir III of Poland founded the Cracow Academy, the second university in central Europe after the University of Prague. There had already been a cathedral school since 1150 functioning under the auspices of the city's bishop. The city continued to grow under the joint Lithuanian-Polish Jagiellon dynasty (1386–1572). As the capital of a powerful state, it became a flourishing center of science and the arts.
Kraków was a member of the Hanseatic League and many craftsmen settled there, established businesses and formed craftsmen's guilds. City Law, including guilds' depictions and descriptions, were recorded in the German language Balthasar Behem Codex. This codex is now featured at the Jagiellonian Library. In 1475 delegates of the elector George the Rich of Bavaria came to Kraków to negotiate the marriage of Princess Jadwiga of Poland (Hedwig in German), the daughter of King Casimir IV Jagiellon to George the Rich. Jadwiga traveled for two months to Landshut in Bavaria, where an elaborate marriage celebration, the Landshut Wedding (Landshuter Hochzeit 1475) took place in St. Martin's church (Landshut). Around 1502 Kraków was already featured in the works of Albrecht Dürer as well as in those of Hartmann Schedel (Nuremberg Chronicle) and Georg Braun (Civitates orbis terrarum). In the adjoining Jewish quarter of Kazimierz, earmarked in 1495 by King Jan I Olbracht for the Jewish community after a fire, some of Europe's oldest synagogues were built. The most prominent of them, the Old Synagogue, now serves as a Jewish history museum.
The Renaissance, whose influence originated in Italy, arrived in Kraków – the capital of Poland until 1596 – along with numerous Italian artists including Francesco Fiorentino, Bartholommeo Berecci, Santi Gucci, Mateo Gucci, Bernardo Morando, Giovanni Baptista di Quadro and others. The period, elevating the intellectual pursuits, produced many outstanding artists and scientists such as Nicolaus Copernicus who studied at the local Academy. In 1468 the Italian humanist Filip Callimachus came to Kraków, where he worked as the teacher of the children of Kazimierz IV. In 1488 the imperial Poet Laureate and humanist Conrad Celtes founded the Sodalitas Litterarum Vistulana ("Literary Society at Vistula"), a learned society based on the Roman Academies. In 1489, sculptor Veit Stoss (Wit Stwosz) of Nuremberg finished his work on the High Altar of the St. Mary's Church. He later also made a marble sarcophagus for his benefactor Casimir IV. By 1500, Haller had established a printing press in the city. Many works of Renaissance movement were created there during that time.
Art and architecture flourished under the watchful eye of King Sigismund I the Old, who ascended to the throne in 1507. He married Bona Sforza of a leading Italian family and using his new Italian connections he began the major project (under Florence architect Berrecci) of remaking the ancient residence of the Polish kings, the Wawel Castle, into a modern Renaissance residence. In 1520, Johan Behem made the largest church bell, named the Sigismund Bell after King Sigismund I. At the same time Hans Dürer, younger brother of Albrecht Dürer, was Sigismund's court painter. Around 1511 Hans von Kulmbach painted the series of panels for the Church of Pauline Fathers at Skałka and the Church of St. Mary. Sigismund I also brought in Italian chefs who introduced Italian cuisine.
In 1572, King Sigismund II died childless, and the throne passed to Sigismund III of the Swedish House of Vasa, contributing to the Commonwealth's future demise. Kraków's importance began to decline, accelerated by the pillaging of the city during the Swedish invasion.
In the late 18th century, the Polish–Lithuanian Commonwealth was partitioned by its expansionist neighbors after a joint invasion of the Commonwealth by the Imperial Russia, Austrian Empire and the Kingdom of Prussia. The conquered Kraków became part of the Austrian province of Galicia. In 1794 Tadeusz Kościuszko initiated an independence revolt, the Kościuszko insurrection in Kraków's market square. The Prussian army put down the revolt, and looted Polish royal treasure kept at the Wawel Castle. The stolen regalia, valued at 525,259 thalers, were secretly melted down in March 1809 while precious stones and pearls were appropriated in Berlin.
When Napoleon Bonaparte of the French Empire captured what had once been Poland, he established the Duchy of Warsaw (1809) as an independent but subordinate state. The Congress of Vienna (1815) restored the partition of Poland, but gave Kraków partial independence as the Free City of Kraków. The city again became the focus of a struggle for national sovereignty in 1846, during the Kraków Uprising. The uprising failed to spread outside the city to other Polish lands, and was put down, resulting in the creation of the Grand Duchy of Cracow by the Austrian Empire.
After the Austro-Prussian War of 1866, Austria granted partial autonomy to Galicia, making Polish a language of government and establishing a provincial Diet. As this form of Austrian rule was more benevolent than that exercised by Russia and Prussia, Kraków became a Polish national symbol and a center of culture and art, known frequently as the "Polish Athens" (Polskie Ateny) or "Polish Mecca" to which Poles would flock to revere the symbols and monuments of Kraków's (and Poland's) great past. Several important commemorations took place in Kraków during the period from 1866–1914, including the 500th Anniversary of the Battle of Grunwald in 1910, in which world-renowned pianist Ignacy Paderewski unveiled a monument. Famous painters, poets and writers of this period, living and working in the city include Jan Matejko, Stanisław Ignacy Witkiewicz, Jan Kasprowicz, Juliusz Kossak, Wojciech Kossak, Stanisław Wyspiański and Stanisław Przybyszewski. The latter two were leaders of Polish modernism.
The Fin de siècle Kraków, even under the partitions, was famously the center of Polish national revival and culture, but the city was also becoming a modern metropolis during this period. In 1901 the city installed running water and witnessed the introduction of its first electric streetcars. (Warsaw's first electric streetcars came in 1907.) The most significant political and economic development of the first decade of the 20th century in Kraków was the creation of Greater Kraków (Wielki Kraków), the incorporation of the surrounding suburban communities into a single administrative unit. The incorporation was overseen by Juliusz Leo, the city's energetic mayor from 1904 to his death in 1918 (see also: the Mayors of Kraków).
Thanks to migration from the countryside and the fruits of incorporation from 1910 to 1915, Kraków's population doubled in just fifteen years, from approx. 91,000 to 183,000 in 1915. Russian troops besieged Kraków during the first winter of the First World War, and thousands of residents left the city for Moravia and other safer locales, generally returning in the spring and summer of 1915. During the war Polish Legions led by Józef Piłsudski set out to fight for the liberation of Poland, in alliance with Austrian and German troops. The Austro-Hungarian and German Empires lost the war, but the terms of the Treaty of Versailles (1919) established the first sovereign Polish state in over a century. Between the two World Wars Kraków was also a major Jewish cultural and religious center (see: Synagogues of Kraków), with the Zionist movement relatively strong among the city's Jewish population.
Poland was partitioned again at the onset of the Second World War. The Nazi German forces entered Kraków on September 6, 1939. The residents of the city were saved from German attack by the courageous Mayor Stanisław Klimecki who went to meet the invading Wehrmacht troops. He approached them with the call to stop shooting because the city was defenseless: "Feuer einstellen!" and offered himself as a hostage. He was killed by the Gestapo three years later in the Niepołomice Forest. Kraków became the capital of the General Government, a colonial authority under the leadership of Hans Frank. The occupation took a heavy toll, particularly on the city's cultural heritage. First, during the infamous Sonderaktion Krakau 184 professors and academics of the Jagiellonian University (including Rector Tadeusz Lehr-Spławiński among others) were arrested at the Collegium Novum during a meeting ordered by the Gestapo chief SS-Obersturmbannführer Bruno Müller. President of Kraków, Klimecki was apprehended at his home the same evening. After two weeks, they were sent to Sachsenhausen concentration camp on the other side of Berlin, and in March 1940 further to Dachau. Those who survived were released only after international protest involving the Vatican.
Many relics and monuments of national culture were looted and destroyed (yet again), including the bronze statue of Adam Mickiewicz stolen for scrap. The Jewish population was first ghettoized, and later murdered. Two major concentration camps near Kraków included Płaszów and the extermination camp of Auschwitz, to which many local Poles and Polish Jews were sent. Specific events surrounding the Jewish ghetto in Kraków and the nearby concentration camps were famously portrayed in the film Schindler's List, itself based on a book by Thomas Keneally entitled Schindler's Ark.
A common account popularized in the Soviet-controlled communist People's Republic of Poland, held that due to a rapid advance of the Soviet armies, Kraków allegedly escaped planned destruction during the German withdrawal. There are several different versions of that account. According to a version based on self-written Soviet statements, Marshal Ivan Konev claimed to have been informed by the Polish patriots of the German plan, and took an effort to preserve Kraków from destruction by ordering a lightning attack on the city while deliberately not cutting the Germans from the only withdrawal path, and by not aiding the attack with aviation and artillery. The credibility of those accounts has been questioned by Polish historian Andrzej Chwalba who finds no physical evidence of the German master plan for demolition and no written proof showing that Konev ordered the attack with the intention of preserving the city. He portrays Konev's strategy as ordinary – only accidentally resulting in little damage to Kraków – exaggerated later into a myth of "Konev, savior of Kraków" by Soviet propaganda. The Red Army entry into the city was accompanied by a wave of rapes of women and girls resulting in official protests.
After the war, the government of the People's Republic of Poland ordered the construction of the country's largest steel mill in the suburb of Nowa Huta. This was regarded by some as an attempt to diminish the influence of Kraków's intellectual and artistic heritage by industrialization of the city and by attracting to it the new working class.
The city is regarded by many to be the cultural capital of Poland. In 1978, UNESCO placed Kraków on the list of World Heritage Sites. In the same year, on October 16, 1978, Kraków's archbishop, Karol Wojtyła, was elevated to the papacy as John Paul II, the first non-Italian pope in 455 years.
Kraków's population has quadrupled since the end of World War II. After the collapse of the Soviet empire and the subsequent joining of the European Union, Offshoring of IT work from other nations has become important to the economy of Kraków and Poland in general in recent years. The city is the key center for this kind of business activity. There are about 20 large multinational companies in Kraków, including centers serving IBM, General Electric, Motorola, and Sabre Holdings, along with British and German-based firms.