The end of the movie "The Departed" culminates with Sergeant Dignum shooting Colin Sullivan as he enters his apartment, despite seemingly resolving all his loose ends. Although the audience does not know exactly why Dignum murders Sullivan, it is logical to assume Dignum was informed about Sullivan being the true undercover infiltrator, or rat, in the FBI. This becomes apparent when Billy Costigan hands a note to Madolyn for unexplained reasons.
Sullivan Betrays Barrigan
Just as Costigan is about to bring Sullivan into custody, Sullivan's fellow mob-member Barrigan shoots Costigan and informs Sullivan that he is also working as a rat in the FBI. He then informs Sullivan that they need to stick together, as their boss (Frank Costello) had intended to turn them in and had been working as an FBI informant. However, Sullivan instead shoots and kills Barrigan. This is presumably because Sullivan had a clean record in the FBI and was held in high regard by his colleagues. Given the option of maintaining a prestigious career in the FBI or becoming a criminal on the run, Sullivan chose the former.
In the ending scenes of "The Departed," Sullivan is seen attending Costigan's funeral and using Barrigan as a scapegoat. Sullivan explains that it was Barrigan who killed Costigan and who was the rat all along -- thus removing any suspicion from himself. This is consistent with Sullivan no longer wanting to live a life in the mob and instead resigning himself to becoming a bona fide member of the FBI.
Despite seemingly keeping his identity as the true rat concealed, Sullivan is murdered by Dignum in the last scene of "The Departed." Viewers are not given a direct explanation as to why; however, one possibility is the note Costigan gave to Madolyn before being murdered. Costigan gives the mysterious note to Madolyn directly after discovering that Sullivan is the rat. The letter's contents remain unseen, however, Dignum's murder of Sullivan suggests the letter asked Madolyn to reveal the truth to Dignum through evidence provided in the letter.
The Rat on the Banister
The term "rat" is used throughout "The Departed" to describe someone who betrays the group they are supposedly loyal to by leaking information to his group's enemies. For example, Sullivan is a rat to the FBI because he is actually loyal to the mob, whereas Costigan is a rat to the mob because he is loyal to the FBI. The rat seen on the banister just before the film ends acts as a symbol for all of the "rats" in the movie.