Why did castles fall into decline?

gunpowder. walls arent much good when you can blow them up.