This is in plain TeX, so you need to run it with pdfTeX. Why do we need 11 expandafters? Is there a rule of thumb for this type of definitions? How many do you need to expand five i.e, to expand \e also which I conveniently spaced out!

\expandafters tend to come in powers of two, minus one: one expandafter is "reach over token once", to reach over the token twice, you need thre:, the first jumps to the third, the third jumps over your token, leaving the second to jump over the second time, and so on.
– Ulrich SchwarzDec 24 '10 at 14:51

1

could one define a \superexpandafter{n} that would expand to 2^n-1 \expandafter's?
– Yossi FarjounDec 24 '10 at 14:54

@Yossi. Only to some extent. You can do this if it is the first thing which needs to get expanded, but imagine \expandafter\SomeToken\superexpandafter{n}. You can't get the \superexpandafter to work 'as expected' here, as it would require at least two expansions to continue the chain past \SomeToken.
– Joseph Wright♦Dec 24 '10 at 15:49

@Yiannis: By the way, there's no need for the two %.
– Hendrik VogtDec 24 '10 at 16:53

With your definition of \a, \b and \c, you don't need all these \expandafters since those macros don't take any arguments. In fact, the above is an oversimplification: In the general case, if the macros do take arguments, the last line above would look somewhat like

\a \once{\b \once{\c \once{\d \e}}}

where \once is not a TeX command but should mean that the argument is expanded once, and the innermost expansion happens first, the outermost last. Here's a really stupid example:

Firstly, \c replaces the , in Hello world!, with :. Secondly, \b replaces the : with ., and finally \a strips the .. In this example, all the \expandafters are needed.

What do 2^n-1\expandafters do?

2^1-1=1\expandafter expands the stuff after the next token once, and by induction you easily see that 2^n-1\expandafters expand the stuff after the next token n times. Moreover, making this happen takes n expansion steps. Let's look again at your code, now from this point of view:

The first 7 \expandafters expand the stuff after \a 3 times. Two of these 3 expansion steps are needed to expand the 3 \expandafters after \a; let's keep in mind that a last expansion step is missing. Before that last step, the 3 \expandafters after \a expand the stuff after \b 2 times. The first expansion yields \c \once{\d \e} after the \b, the second one yields \once{\c \once{\d \e}}. This completes the description of two of these 3 expansion steps. In the third of these 3, the stuff after \a is expanded one last time.

In TH's comment, the 3 \expandafters expand the \csname bar\endcsnametwice, thus yielding the expansion of \bar. Another important case is

And sometimes \expandafter\expandafter\expandafter\foo\csname bar\endcsname is useful. That is, expand \bar once before \foo even though \bar is constructed using \csname ... \endcsname.
– TH.Dec 24 '10 at 17:18

To expand on the same theme as TH.'s comment to Hendrik's answer, when you must use lengthly \expandafter chains, you can exploit constructions like \csname...\endcsname (or, in some contexts, \number) which completely expand things by placing the right number of \expandafters just after/before the token you want to expand, e.g.

will be the same as \macroone followed by \macrotwo expanded two times.

To give a concrete example, suppose you have \a\b\c\d\e and want to expand \e three times, \c two times, and \a, \b, \d one time. With the \csname...\endcsname method, it would be (here, we store the result of expansion inside a \temp macro and then \show it to see clearly what was expanded; you need the three \expandafter in the \def\temp because the first token needs two expansions):