Snape's true motivation and loyalties were issues that were only definitively resolved in the last book, though hints were given out in most of the books up to that point. Snape is by far the most complicated and no doubt some would say the most interesting character in the series. Rather like Gollum in The Lord of the Rings.