The vessel's speed is either measured concerning water or ground.
Speed over Ground (SOG) is the vessel's speed in one hour concerning the land or any other fixed object such as buoys.
Speed through Water (STW) is the vessel's speed in one hour concerning the water or anything floating on water.
There is no wind and no current. The vessel is showing a speed of 10 knots. It is near to the land, and there is a boat near the land which is not moving. In one hour, the vessel will cover 10 nautical miles (nm) between the land and the floating boat. This is because there is no wind or current, and the floating boat will maintain its position. Speed over Ground (SOG) and Speed through Water (STW) is the same, 10 knots.
All conditions are the same. But now there are 2 knots current from ahead. The vessel starts moving at a speed of 10 knots. In this case, the vessel will only cover 8 nautical miles in one hour because of adverse currents. So when measured from the land, the ship has only moved 8 nautical miles, and the SOG will be 8 knots.
Because of 2 knots, ahead of the current, the boat that moved 2 nm away from the ship, the distance covered by the vessel concerning the floating boat will be 10 nm. So the STW will be 10 knots.
All other conditions are the same. But now there are 2 knots current from astern. The vessel starts moving at the speed of 10 knots. In this case, the vessel will cover 12 nm in one hour because of the favorable current. When measured from the land vessel has moved 12 nm. So SOG will be 12 knots. Because of the 2 knot current, the boat would move 2 nm in the vessel's direction. The distance covered by the vessel concerning the floating boat will still be 10 nm. So the STW will still be 10 knots.