You go to the settings application on your home screen and tap on general. You tap on general and on the top, you should find the about tab. The about tab tells you every detail of your iPhone including your device
Go to "Settings" , "General", "About" and check what is written in front of the "Version" field. You should see something in this format: 3.1.3 (7E18), which in this case indicates you would have iOS 3.1.3.