I'm pretty sure this question has a very simple answer and I am just not understanding the geometric picture very well, however I can across a question on the gradient operator which made me a bit unsure as to what it does. The gradient of a scalar field points in the direction of greatest rate of change. Now if I have a surface given by $f(x,y,z)$, then the normal to the sruface can be found by taking the gradient of $f$ at that point. Intuitively, this also makes sense to me. The change is zero along the tangent plane, so the greatest rate of change must be normal to the surface.

However I was doing a question which gave a surface and then asked in what direction a marble would roll if placed at a particular point on the surface. Now I initially thought that the marble would roll in the direction of greatest rate of change- i.e. a ball on a hill will roll down where the potential will decrease most rapidly. I would take the gradient and then take the direction in which f was decreasing as opposed to increasing.

However if the gradient is normal to the surface, then a marble would be ejected directly off of the surface? This is not what happens!

Now I have a hunch as to what might be the problem here although I am not sure. I think the problem is two-fold. First, the mathematical description allows the possibility of the marble passing through the surface or coming off of it. Secondly, I think maybe I am mixing up surfaces and scalar fields which are not surfaces. Perhaps in the physical case I actually have a scalar field (not a surface) describing the potential energy AND a surface on which the marble is constrained to move, and the marble will move in the direction of greatest rate of decrease of potential energy while still being constrained on the surface.

That seems about I think right...

In the first case, your curve is given by $f(x,y,z)=0$. Only then will $\nabla f$ give you the normal to the curve at a point. The reason for this is that $\nabla f$ points you in the direction of maximum increase of f and if it were not normal, it would have a component along the curve and the value of f along the curve would change, which contradicts the curve being the set of those points where $f(x,y,z)=0$.
In the second case you wish to express z in terms of x and y. Only then when you take the gradient $\nabla z$, NOT $\nabla f$ will you be pointed in the region of steepest increase. The difference is you want the steepest increase in z, not f.
Your surface, let's call it $S,$ is not given by $f(x,y,z),$ but by an equation of the form $f(x,y,z) = \text { constant }.$ (Perhaps that's what you meant, but it's good to be clear on this.) If we think of the $z$ variable as representing altitude, we can do this: Let $p\in S.$ What you are looking for is the unit vector $(a,b,c)$ tangent to $S$ at $p$ with the smallest value of $c.$ That unit vector will point in the desired direction.