They did it with a little thing called forced perspective.

For example, in this scene where it looks like Frodo is sitting next to Gandalf, Elijah Wood is actually sitting a fair bit behind Sir Ian.
[Linked Image from]

The actors who played the hobbits aren't very tall but none of them is quite that short. Filmmakers are very tricksy.

Optimistically Apocalyptic