An iron nail sinks in water because the density of iron is greater than the density of water, so the weight of the nail is more than the upthrust of water on it.
On the other hand, the ship is hollow and the empty space in it contains air which makes it volume large and average density less than that of water. Therefore, even with a small portion of ship submerged in water, the weight of water displaced by the submerged part of ship becomes equal to the total weight of ship and therefore, it floats.