Optical image stabilization (OIS) we can see in high-end flagship smartphones in camera specs. The optical image stabilization technology is, of course, useful for smartphones to take good videos and pictures in any lighting condition without shaking. When you are taking a photo you may notice a sound known as shutter sound. This shutter is present before the sensor in a camera. When taking a photo this shutter will open and close, for that denoting that sound is added to it. In the daytime, the shutter will open and close quickly because enough light is present in the environment to take a photo. In the day time, the shutter speed will be very high. At night time there will be no enough light so the shutter will not close quickly to give enough light to the sensor for taking a photo. In night condition the shutter speed is very low. If you observe, the camera cannot take the picture quickly at night when compared to day time.
When the shutter takes more time to take a photo in night at that time due to the time your hand will shake and the resultant picture will have much noise (blur). To avoid that shaking Optical stabilization is used. If your phone has optical stabilization when taking a photo in the night time or daytime if hands shaked the OIS will keep the shutter stable and will provide good quality pictures.
When OIS is ON if you shake your hand on the left side the springs will push the sensor and shutter to the right side. Similarly when your hands shaked upwards then it will push too downwards. Like this, it works. This mechanism also works in video mode to keep the video stable.
The total working mechanism is shown below in a video format.