To add to what Richard has said ...
Think of recursion as a set of Russian Dolls (or Matryoshka Dolls)
] Each contains within it another Matryoshka until you get to smallest possible. To access each, you open the doll and extract the next size down.
Your function just implementing the string definition of a factorial:
5! = 5 * 4!
4! = 4 * 3!
3! = 3 * 2!
2! = 2 * 1!
1! = 1
So from that: when N is greater than 1, return N * factorial(N - 1). Otherwise, return 1
function checks if N is 1 and returns 1 if so, otherwise it multiplies N by (N - 1) factorial by calling itself. The (direct or indirect) "function calling itself" bit is called
, and it's a powerful technique - though not often used in practice as it has some significant problems in the real world.
Run it through the debugger and you'll see what I mean.
As a recursion demonstration using factorials works, but it's really a poor example of recursion: a loop would have been a lot more efficient.