First, we must acknowledge that we cannot know what the average soldier believed because we do not have anything like opinion polling from the time. Different soldiers certainly fought for different reasons, with some fighting because they had to, others for adventure, and so on.
In general, though, we can say that most Union soldiers were fighting to preserve the Union and most Confederates were fighting for the idea of states' rights. The Confederates felt that their rights were being infringed upon by the federal government and wanted to break away. The Union soldiers believed in the idea that the South had no right to break away.