To answer the question, let's look at a specific example. On the movie Thor (2011), the writing credits read:
Ashley Edward Miller & Zack Stentz and Don Payne
J. Michael Straczynski and Mark Protosevich
To untangle these credits, there are a number of points to you need to understand:
- When two names are separated by an ampersand (&), it designates a writing team. So Ashley Edward Miller & Zack Stentz are two writers who work as a team.
- When two names are separated by "and" that means that the writers did not collaborate as a team, but rather contributed to the script at different times during development. Perhaps one rewrote an earlier draft by the other.
- The order of names indicates the weight of the writer's contribution to the final shooting script. The name that comes first contributed more.
- Sometimes credit is split into "story by" and "screenplay by." The WGA defines "story" as a contribution "distinct from screenplay and consisting of basic narrative, idea, theme or outline indicating character development and action."
- On a script (like Thor) that has been in development for many years or even decades, dozens of different WGA writers may be hired to work on the script at different times, but only two writers (or writing teams) can get credit. In the case of Thor, a writing team and a single writer split screenplay credit, and two writers split story credit.
- When a screenplay is non-original (based on underlying material, as Thor was based on a comic book), a credited writer must have contributed 33% or more to the final shooting script. For "screenplay by" credit the writer must contribute 33% in the areas of character, structure, dialogue, and "new and original scenes."
- When a screenplay is original, the first writer gets sole credit, unless a subsequent writer has contributed 50% or more to the final shooting script.
- When a credit reads "written by," it means that the writer(s) is responsible for both story and screenplay. For example, on Conan The Barbarian 3D, the credits read: written by Thomas Dean Donnelly & Joshua Oppenheimer and Sean Hood. So, the writing team Donnelly & Oppenheimer share both story and screenplay credit with Sean Hood (me.)
- Often final credits are determined by the WGA in a grueling and complex arbitration process. (See Screenwriting Credit System)
In the case of Thor in particular, I know that Mark Protosevich was hired by Marvel Studios to write the script in 2006, and he did another draft in 2008. However, when Kenneth Branagh was hired to direct it, other writers were hired to do rewrites. Also Thor had been "in development" since 1990, so its possible that some of the writers who worked on scripts before Protosevich were eligible for credit. Since Protosevich did not get "screenplay by" credit it seems that only some general elements of "story" remained in the final shooting scripts after many rounds of rewrites.
But who is really responsible for what? Having been through several WGA credit arbitrations (including one for Conan The Barbarian 3D) I can say that each writer may have very, very different ideas about who deserved credit for what, and who "really" wrote the script. Check out this New Yorker article on credit battles.
Also, check out this story: George Clooney was furious when the WGA decided not to award him credit on Leatherheads, a script that he claims he completely rewrote: WGA, Clooney at odds over credit