The density of nail (as of iron) is much larger than the water. So it sinks easily. The weight of the water displaced by the ship is equal to its weight, so it floats. Whereas the weight of the waterdisplaced by the iron nail is less than its weight so the iron nail sinks.