Within or inside?

Solution 1:

Both words refer to the interior of a three-dimensional concave surface; i.e, a container.
But they don't refer in the same ways; there's a lot of differences. @tchrist pointed some out.
Others include:

  • because inside is a noun (but within isn't), one can construct complex prepositions like
    glue the paper to the inside of the box

  • similarly, because it is a noun, inside can function as an adjective, as in the inside front cover, or in noun compounds like inside man or inside information.

  • inside, but not within, often uses of to mark its object:
    He got here inside (of) a minute but not *He got here within of a minute.

  • inside contrasts with outside, but within contrasts with without.
    These are quite dissimilar contrasts. For one thing, they don't do negation the same way.

    • They stood there within easy earshot, but without any comprehension at all.
    • Outside of a dog, a book is a man's best friend. Inside of a dog it's too dark to read.
      –   Groucho Marx

Solution 2:

Both can be used as prepositions or adverbs, but only inside can function as a noun or an adjective.

So for example:

  • You can talk about the inside of something, but never its *within.

  • You can have an inside job, but never a *within job.

Solution 3:

To say 'they are the same' would mean they are interchangeable and in 90% of the cases they are not. The only time within can replace inside is in highly formal context - ' office assistant is needed, apply within'. But most frequently within is used for its own sake to mean 'in limits/reach of something', e.g. - within a hundred metres of each other, within walking distance, within someone's reach, etc..