'In' is used to describe the exact location of where someone or something actually' is/was' or does/did something. I live 'in' a house. The TV is 'in' the sitting room. It is often used instead of 'inside'. Where's the sugar? It's in/inside the cupboard.
We use 'at' for more general location. I study 'at' University (Usually without 'the' unless your're referring to one specific university.') is correct because you are not referring to your exact physical location.
"I study at university" , "I study at the university of..." or "I study at (the name) University"
The rule is to use "at", just like when saying "I work at (name of the firm or institution)" rather than "in", in these cases.