The Stanley Parable has two endings: the "good" ending and the "bad" ending. The good ending is the one where Stanley chooses to rebel against the Narrator, and the bad ending is the one where Stanley chooses to do what the Narrator tells him to.
To get the good ending, you need to make sure that Stanley goes through all the doors in the game, including the one that takes him back to the start. Once he's done that, he'll be able to go through the door to freedom.
If you want to get the bad ending, simply have Stanley do everything the Narrator tells him to. Eventually, he'll be led into a room with a button, and pushing that button will trigger the ending.