When designing a woodworking project, I've occasionally been asked, "How do you determine the size and length of screw to be used on the project?"
The answer isn't really cut and dried, but I do follow a few guidelines. The idea is to use screws that are long enough and stout enough to hold the two boards together securely, without being so large that it splits the stock receiving the screw, or so long that the tip of the screw pokes through the backside.
Second, the fasteners need to have enough thread into the receiving stock to hold fast. The length of the thread that is inserted into the receiving board is really dependent on what forces will be applied to the boards in question when in use. If the forces will apply lateral pressure, consider using a thicker screw than you might otherwise choose. However, if the forces will want to cause the boards to separate, be sure that ample screw threads are inserted into the receiving board.
In the latter case, I always to try to get at least 1 to 1-1/2 inches of thread into the receiving board. This assumes, of course, that this length of screw won't poke through the opposite side of the board. In the event that you need shorter screws to prevent this problem, you'll need to supplement with an increased quantity of screws.
Additionally, the number and length of screws that are used will depend on the grain orientation of the receiving board. As a general rule, screws needed for attaching two boards across the grain will not need to be as long as when screws are inserted into end grain. When screwing into end grain, I try to get at least two inches of thread into the board.
As a general rule, I tend to use #8 diameter deck-type screws for most tasks. I'll have 1-1/4" screws for basic tasks where strength isn't a huge issue or when attaching two 3/4" thick boards across the grain. I also like to keep some 2-1/2" deck screws for screwing into end grain, plus some beefy 3" screws for attaching two-by stock into end-grained boards, or when a little extra added oomph is needed. Finally, if there will be a lot of sheer strength needed, I may opt for some 1/4" diameter lag screws.
Here's a reference that, while a bit complicated, is useful for determining what size screws should be used. The American Wood Council has posted a Connection Calculator that can be used to determine the connection capacity of certain types of fasteners when used in specific connection types with specific members.
TIP: No matter whether I'm inserting screws into end grain or cross-grained boards, I always try to pre-drill the holes with a special bit that drills a small hole the length of the screw thread as well as a counter-sink that will allow the head to be sunk flush with the surface.