After Lucifer was banished from Heaven for defying God due to his corruption from the Mark of Cain, he twisted a human soul into the first demon. After this, God sent Michael to imprison Lucifer in the Cage which was locked with 600 mystical seals.
In 1972, Azazel possessed a priest at St. Mary's Convent, and killed eight nuns in the chapel. This enabled him to speak to the imprisoned Lucifer. Lucifer tells Azazel that Lilith is needed to break the 66 Seals that hold him captive in the Cage and that he needs to find a very "special child." This leads Azazel to recruit select children, including Sam Winchester and to set in motion events that subsequently lead to the breaking of the 66 Seals.
In 2008, after Dean's return from Hell, Castiel reveals that Lilith is trying to break the seals that lock the Cage in order to free Lucifer. Dean later learns that the first seal was broken when he was in Hell, and broke under torture and began torturing souls himself. Sam continues clandestine missions with Ruby, developing his powers even though this involves drinking demon blood, believing that killing Lilith will stop the Cage being opened. In 2009, Sam unknowingly releases Lucifer from the Cage by killing Lilith at St. Mary's Convent. Lilith is revealed to have been the last of the 66 Seals.
As Sam and Dean attempt to find a way to stop Lucifer and the impending Apocalypse, Gabriel tells them that the Four Horsemen of the Apocalypse all own rings that together can reopen a portal to the Cage anywhere. After collecting all the rings, Sam comes up with a plan in which he will allow Lucifer to possess him, and then force him into the Cage. The initial attempt fails, but when Lucifer confronts Michael at Stull Cemetery, Sam activates the rings and as the Cage opens, he manages to gain enough control to force himself (and Lucifer) into the Cage. Michael (in possession of Adam's body) tries to stop him but is dragged into the Cage as well.
After the averted Apocalypse, Raphael tried to reopen the Cage to release Lucifer and Michael, to continue where the angel's plans lefy off, but was ultimately unsuccessful due to Castiel leading a civil war in Heaven to stop him. During this time, Sam is subsequently rescued from the Cage by Castiel, but his soul remained trapped in the Cage being tortured by Lucifer and Michael. Death agrees to retrieve Sam's soul, and returns it to his body, setting up a temporary "wall" in Sam's mind to prevent the knowledge of the horrors that happened in the Cage from destroying him.
Following the release of the Darkness, cries are heard coming from the Cage, and the demons speculate that Michael or Lucifer are trying to warn them about it. Sam also starts having flashbacks or visions of his torment in the Cage. When Sam finally journeys to Hell to confront Lucifer with Crowley and Rowena, he learns that the impact of the Darkness' release had a massive effect on Hell, causing the Cage to become damaged. It was through those fissures Lucifer was able reach out and give Sam his visions of the Cage. Lucifer is eventually able to escape in 11.10 The Devil in the Details by taking Castiel as his vessel, leaving Michael, who had become catatonic due to his imprisonment, alone in the Cage.
Each of the Four Horsemen of the Apocalypse own individual rings that together form a key-like device that can reopen a portal to the Cage. Death described it as a "fiery pit" and during his time in the Cage, Sam is seen surrounded by eternal flames. 
Communication is possible from the Cage -- Lucifer is able to talk to Azazel, after Azazel performs a specific ritual on Earth that allows Lucifer to speak through a conduit. After the Darkness is released, Crowley's minions report hearing cries coming form the Cage.
Where Is the Cage?
The exact location of the Cage was originally quite vague. It seemed to be of the same realm of Hell, though obviously separate from the part of Hell where demons are produced, as it took great effort for even Azazel to establish communication with Lucifer. Dean is able to open the Cage via the Horseman's rings in a deserted building and Sam uses them to open the Cage in Stull Cemetery. It was conjectured by fans that, since the Cage could be entered from multiple locations, it may exist on a different dimensional plane.
However, Sera Gamble later confirmed that the Cage is, "At the bottom of the lowest depths of the ninth circle of the worst bit of Hell." In season 11, the Cage is finally shown to be a box hanging by multiple chains surrounded by black storm clouds.
Dean: Why break the seal anyway?
Castiel: You think of the seals as locks on a door.Castiel: Lucifer walks free.
Dean: Okay, last one opens, and?
Castiel explains to Dean that if Lucifer ascends from the Cage, Hell and chaos will follow his presence on Earth. He later elaborates by saying that all of creation will literally experience Hell if[Lucifer roams Earth.
And it is written that the first seal shall be broken when a righteous man sheds blood in Hell. As he breaks, so shall it break.
Castiel and Uriel ask Dean to torture Alastair to find out who is murdering angels. In the process, Alastair revels that it was Dean who broke the first seal of Lucifer's Cage.
And it is written that the first demon shall be the last seal.
Ruby helps Sam find a demon who can reveal Lilith's location. In preparation for confronting Lilith, Ruby encourages Sam to drink the demon blood (killing the woman it is possessing in the process). At St. Mary's Convent, Sam uses his powers to kill Lilith, only to have Ruby reveal that Lilith is actually the final Seal holding the Cage secure. Lilith’s blood forms a spiral circle in the middle of the chapel at St. Mary's Convent and the gates of Lucifer’s prison open and Lucifer is released into the world.
Following Sam Winchester's actions of killing Lilith the first demon, a direct portal to Lucifer's Cage opens, which releases Lucifer where he ascends from its bowels, soon arriving on Earth. While Lucifer rises from the Cage, his mere essence launches a bright white column of light from the shaft of the Cage.
Without me, you got zero shot at killing Lucifer. Sorry. But... you can trap him. The cage you sprung Lucifer from, it's still down there, and maybe, just maybe, you can shove his ass back in. Not that it'll be easy. You got to get the cage open, trick my bro back into it, and oh yeah, avoid Michael and the God Squad. But hey - details, right? And here's the big secret, Lucifer himself doesn't even know. But the key to the cage, it's out there. Actually it's keys, plural, four keys. Well, four rings from the Horsemen. You get 'em all, you got the cage.
Sam and Dean try to kill Lucifer with the Colt but fail, and are desperate for a solution. In a hidden message recorded on a Casa Erotica DVD, Gabriel reveals posthumously how Sam and Dean can trap Lucifer back in the Cage, by using the rings worn by the Four Horsemen of the Apocalypse, which act as keys to the Cage.
Crowley reveals he is aware of Sam and Dean's plan to get the Horsemen's rings to trap Lucifer back in the Cage thanks to his magical coin. He also tells them he wants to help them do it. Sam comes up with a plan -- he could consent to Lucifer's possession, and with much determination he could resist Lucifer for a brief moment; which would give him time to jump into the Cage with Lucifer inside of him. Bobby and Dean are both against the idea.
Sam and Dean get the final two rings after Castiel cuts off Pestilence's finger using Ruby's knife and Death gives his ring to Dean in exchange for his promise to do whatever it took to free him from Lucifer's control, ensuring that Sam would jump into the Cage as soon as he consented to possession by Lucifer. Death also instructs Dean on how the rings work to open the cage, although the explanation is not shown in this episode. Dean is later shown working with all four rings on a table. They join together to form a triangular shape with War's ring in the center and the other three rings surrounding it. When Bobby asks him about Death teaching him how the rings work, Dean responds, "Yeah, it's nuts."
Bvtmon Tabges Babalon.
Dean finally agrees to support Sam's plan though he has deep misgivings telling him, "Your Hell is gonna make my tour look like Graceland." Sam primes himself by drinking demon blood and then they confront Lucifer. Lucifer knows of their plan, but Sam says "yes" anyway. As Lucifer takes him over, Dean uses the ring and an incantation to open the "door" to the cage. However Lucifer is in control, and he easily closes it.
Later, in Stull Cemetery, Lucifer faces Michael who appears using Adam Milligan as a vessel. Lucifer tries to dissuade Michael from the fight, blaming their conflict on God, and suggesting they walk away. Michael counters that he must carry out God's orders, and that it's his destiny to kill Lucifer, who is evil. Just then Dean arrives in the Impala, Def Leppard's "Rock of Ages" blaring. Dean tries to talk to Sam, inside Lucifer, but Michael tells him it's not his fight anymore. Castiel arrives and throws a Molotov cocktail made with holy oil at Michael, causing him to vanish temporarily. Lucifer turns and blows Castiel up with a snap of his fingers. Then, as Bobby begins shooting him, he snaps his neck.
Lucifer starts to beat Dean, taunting him, saying he will kill him slowly and make Sam feel it. Dean doesn't resist, just telling Sam he won't leave him. As he goes to land another blow, he glances at the Impala, and suddenly all Sam's memories of life with Dean rush at him, allowing Sam to take control over Lucifer. He tosses the Horsemen's rings to the ground, recites the incantation to open the Cage. He and Dean look at each other one last time, but as Sam goes to throw himself in, Michael reappears. Michael tries to stop him, but Sam drags him into the chasm too, and it shuts.
I don't want to talk about it. I get to breathe fresh air, have a beer, hunt with my family, see you again. So why exactly would I want to think about Hell?
Sam reveals that he escaped the Cage soon after tumbling into it. He tells Dean he remembers his time there, but when Dean asks, he doesn't want to talk about it. Dean speculates that God may have brought him back.
Dean tells Bobby that Sam has been different ever since he was released from the Cage. He speculates that Sam may still be a vessel for Lucifer but Castiel denies this, and says that if Lucifer was on Earth, he would've felt his presence.
The Leprechaun is able to make deals with humans so that they may fulfill their wishes. Appearing to be very powerful, he employs what he calls "real magic." He claims to be able to lift Sam's soul from Lucifer's Cage, and scoffs when Sam mentions that not even angels could accomplish that saying that fairies, "Got a way of gettin' in back doors."
Castiel tells Dean that Sam's soul, having been tortured by Lucifer for over a year, may be irrevocably damaged. Crowley also confirms this.
Dean has himself purposefully "killed" under medical supervision, so he can plead with Death to rescue Sam and Adam from the Cage. Death agrees to rescue only one of them -- Dean chooses Sam. Death makes a wager with Dean, that if he will wear Death's ring for one day, and perform his duties, then Death will rescue Sam's soul. he tells Dean that he will be able to contain the part of Sam that will be damaged from his time trapped with Michael and Lucifer behind a "wall" in Sam's mind, although he can't guarantee how long this will maintain. Although Dean fails to wear the ring for a day, Death agrees to retrieve Sam's soul, which he returns to Sam.Dean resolve the murders, Sam falls onto the floor, shaking uncontrollably, where he recalls some of the torture he endured in Hell by Lucifer, where he is seen covered in flames.
Sam asks Dean how long he was unconscious while he was experiencing a brief flashback of his time spent in the Cage. Dean tells him it was 2-3 minutes. Sam tells him it felt like a week.
After Dean, Sam and Bobby learn from Eleanor Visyak that Castiel has enough information to open a doorway to Purgatory wide open, Castiel appears and asks them to leave, but when Dean refuses, he touches Sam's forehead, cracking the wall that Death planted there in the process.
Immediately after the incident, Sam lies unconscious on a bed in Bobby's Panic Room. Although unbeknownst to him at the time, as he thinks it is all real, Sam is actually going through mental experiences, where he first fights a soulless version of himself, kills it and absorbs its memories, a while later, he confronts a version of himself that recalls all of what happened to him the Cage, this version doesn't fight Sam, but warns him about the cost of remembering before allowing Sam to kill him. As Sam gets flooded with those experiences from the Cage, he is able to wake up. Once awake, he goes to assist Dean and Bobby, and on the way, he has mental visions of Hell, but somehow manages to overcome them.
After the Darkness was released, an animalistic scream was said to have been heard originating from the Cage. As was reported to Crowley, at least half of Hell shows concern that either Michael or Lucifer were trying to warn everyone of the coming of the Darkness.
Sam has a vision of when he was tortured in the Cage, with hooks in his flesh being pulled apart by chains.
Sam has another vision or flashback of Lucifer's Cage.
Sam has yet another vision of being in the Cage, this time he is face to face with Lucifer who simply places his hand on Sam's cheek. Sam and Dean summon Crowley about gaining access to the Cage, when he says he is incapable of opening it, as the Cage is of "divine manufacture," he does tell them of a possible way speak with Lucifer without opening the Cage, which involves the information being recorded in one place: the Book of the Damned.
Having captured Rowena; Sam, Dean and Crowley make a deal with her -- she figures out a way to communicate with Lucifer without opening the Cage, and Crowley will call off his assassins. Having studied the Book of the Damned, Rowena finds a spell that will work for what they need. Sam, Rowena and Crowley gather the ingredients needed and descend to the furthest reaches of Hell -- Limbo, where they will perform the spell to allowing communication with Lucifer in relative safety.
After getting a hyperbolic pulse generator from Arthur Ketch of the British Men of Letters, the Winchesters, Castiel, Crowley and Rowena team up together to return Lucifer to his cage. Using President Jefferson Rooney/Lucifer's mistress Kelly Kline, the group lures Lucifer to a motel where Sam uses the hyperbolic pulse generator, a device capable of expelling a demon from their vessel. The powerful pulse beats Lucifer back, as Rowena casts a spell to send Lucifer's essence back to the Cage. After exchanging words with Sam, Lucifer vacates the president's body, his essence swirls below the ceiling before going through a heating vent in the floor.