This is the formula for the schedule for a 20 team, 4 division league in which each team plays division opponents twice and all other teams once.

First, teams need to be grouped by division and numbered, 1 through 5 in each division and 1 through 20 for the entire league. Other than that it's not essential that you put them in any particular order, but listing them by the order of last year's finish helps assure that teams won't end up playing each other in the same weeks each year. Conversely, listing them in some static way, like alphabetically, will make it more likely that the schedule will be static and many teams will play each other in the same week each year. I'll use the 2010 schedule as an example:

DiMaggio Division
1 (1) Angry Ligers
2 (2) Michigan Wolverines
3 (3) Stubborn Jalapenos
4 (4) Evil Empire
5 (5) Bad Apples

Gehrig Division
6 (1) Moose Knuckles
7 (2) Romanian Yankees
8 (3) Carolina Force
9 (4) Larrupin' Lous
10 (5) Babe's Swinging Blasts

Mantle Division
11 (1) Those Magnificent Men in Their Deep Blue Stirrups
12 (2) Rhode Kill
13 (3) The Lumberjacks
14 (4) Boras's Holdouts
15 (5) New York Squeaks

Ruth Division
16 (1) Harry the K's Legends
17 (2) Rodents of Unusual Size
18 (3) Guys With Wood
19 (4) Naked Truth
20 (5) Springfield Nuclear Powerplant

Note that each team is assigned two numbers, 1-5 in the division and 1-20 in the league. You may also notice that they aren't exactly in the order of last year's finish. This is because 'grudge matches' played during the post season end up counting in the standings, but it's not of much importance schedule-wise. It's also not important which order you put the divisions in. I listed them alphabetically, but you can put them in any order you like.

Step two is fill in the schedule. Below is a week by week schedule broken up into 4 distinct periods. The first four weeks are non-division play (Early Season). Weeks 5 through 9 are the First Divisional Games. Weeks 10 through 18 are non-division games (The Dog Days). Finally, weeks 19-23 are the Second Divisional Games.

Weeks 1 through 4
Week1
1 @ 11
2 @ 12
3 @ 13
4 @ 14
5 @ 15
6 @ 16
7 @ 17
8 @ 18
9 @ 19
10 @ 20

Week 2
20 @ 1
16 @ 2
17 @ 3
18 @ 4
19 @ 5
15 @ 6
11 @ 7
12 @ 8
13 @ 9
14 @ 10

Week 3
10 @ 1
6 @ 2
7 @ 3
8 @ 4
9 @ 5
20 @ 11
16 @ 12
17 @ 13
18 @ 14
19 @ 15

Week 4
15 @ 1
11 @ 2
12 @ 3
13 @ 4
14 @ 5
20 @ 6
16 @ 7
17 @ 8
18 @ 9
19 @ 10

Weeks 5 through 9: the First Division Period
Week 5