Henry IV and Gregory VII had spent two years escalating a dispute over who appointed bishops. Gregory excommunicated Henry, which released his nobles from their oaths of loyalty and left him facing a revolt he could not win. He needed the excommunication lifted, and to get it he needed to be in a room with the pope.
Getting to the door
Gregory was travelling north to meet the German nobles — a meeting that would have gone very badly for Henry — and stopped at Canossa, a fortress belonging to his ally Matilda of Tuscany. Henry crossed the Alps in the depths of winter with a small party to intercept him, which was itself dangerous and impressive and widely reported.
He then arrived at the gate and was not admitted. The accounts describe him waiting three days in the snow, barefoot, in a penitent's hair shirt, asking to be received.
It worked, in the narrow sense
On the fourth day Gregory received him, absolved him, and lifted the excommunication. As a canonical matter a priest confronted by a penitent has very little room to refuse, which is exactly why Henry chose that form: he did not petition as a king, he presented as a penitent, and by doing so removed the pope's ability to say no.
It cost him three days of public humiliation and bought him the thing he actually needed — the German revolt lost its legal footing, and he spent the next several years winning the civil war.
And then it didn't
The two fell out again within three years. Henry was excommunicated a second time, marched on Rome, installed a rival pope, and had himself crowned emperor. Gregory died in exile in Salerno in 1085.
The underlying dispute over investiture ran on until a compromise in 1122, long after both men were dead. Canossa settled nothing structural; what it did was get one man into one room at a moment when that was the only thing standing between him and losing everything.
What people get wrong
"Going to Canossa" has come to mean abject, total surrender — the phrase entered German politics in the 1870s and stuck. It reads better as a calculated manoeuvre that worked: Henry gave up three days of dignity and got his throne back, then resumed the fight and eventually drove Gregory out of Rome. The barefoot-in-the-snow detail is also thinner than it sounds; the chroniclers who report it were writing for one side or the other, and the surviving accounts do not agree on the staging.
He did not petition as a king. He arrived as a penitent, because a priest cannot turn a penitent away.

