If I have a big universe that I need to set up, with lots of characters, lots of locations, magic rules, technology, government rules, is it okay to introduce and explain all of this at the beginning? How much of can be introduced at the beginning without making it boring? How many pages of setting up a universe is too much given the fact that it is pretty complex and lots of things need to be explained?
Explain what needs to be explained as it becomes relevant rather than trying to present all the information in one go. This has certain advantages:
it avoids dumping all the information on the audience in one indigestible lump.
it actually makes the world feel bigger.
Info-dumps tend to bore readers to tears so avoid them: instead tell your readers the rules of magic that have bearing on a casting in progress, or describe a particular world only when the protagonist reviews the data files on it. Explaining your world one piece at a time tells the audience without actually saying it that the universe is too big and too complex for any one person to know all about it, or indeed all about any part of it. The example that came to mind when I saw this question was the Night's Dawn Trilogy, in almost every section of the story we're presented with information about the universe, but very few if any sections of the narrative are pure exposition.
You want to spend as little time as possible on "setup". Even one page of nothing but setup is too much.
The reason for that is that the reader is not yet invested in your story. You'd be forcing a reader to read something akin to a fantasy-encyclopedia about something he has no reason to care for. That's boring, readers aren't going to do that.
Instead, you can introduce elements of worldbuilding organically, as the story demands them. Introduce a character (not necessarily the protagonist, but someone for the reader to follow) straight away, and through him introduce the world bit by bit.
One example, and the reason I mentioned the character we follow in the first chapter doesn't need to be the protagonist, is Harry Potter:
Mr and Mrs Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much, They were the last people you'd expect to be involved in anything strange or mysterious, because they just didn't hold with such nonsense. (J.K. Rowling, Harry Potter and the Philosopher's Stone, chapter 1 - The Boy Who Lived)
Following Mr. Dursley through his day, we are introduced to various strange occurrences. By the end of the first chapter, we know there's "our world", there's magic, which is hidden from the "normal people", and that's pretty much it. Much later, throughout seven novels, we continue to discover the structure of the magical education system, legal system, what magic can and can't do, etc. It isn't dumped on us all at once, before we even learn there's a boy named Harry. Instead, once we have a character we enjoy following, we experience the wonder of the magic world through the character.
Another example, The Hobbit:
In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a hobbit-hole, and that means comfort.
It had a perfectly round door like a porthole, painted green, with a shiny yellow brass knob in the exact middle. (J.R.R. Tolkien, The Hobbit, chapter 1 - An Unexpected Party)
Tolkien needs to introduce a worldbuilding element straight away - what are hobbits, what kind of place does the story start in. So he does that, in a way that's engaging, and creates a vivid image in the reader's mind. But that's pretty much the only element Tolkien introduces straight away. We are not treated to the whole History of Middle Earth before the start of the story. Indeed, even Gandalf is introduced as "a wizard" - we do not learn of his role in the world until much much later.
In The Left Hand of Darkness, Ursula Le Guin needs to introduce that's even stranger to us than Middle-earth.
It starts on the 44th diurnal of Year 1491, which on the planet Winter in the nation Karhide was Odharhahad Tuwa or the twenty-second day of the third month of spring in the Year One. It is always the Year One here. Only the dating of every past and future year changes each New Year's Day, as one counts backwards or forwards from the unitary Now. So it was spring of the Year One in Erhenrang, capital city of Karhide, and I was in peril of my life, and did not know it. (Ursula K. Le Guin, The Left Hand of Darkness, chapter 1 - A Parade in Erhenrang)
What Le Guin told us here is "we're in a different world, take nothing for granted". Actual worldbuilding elements come later, when they become relevant to what's going on right now. And already early on, she placed a hook - "I was in peril of my life, and did not know it." Now there's already a character, we're already invested (we want to find out what's endangering the character's life), in any exposition that comes next we'd be looking for clues. Even the whole kemmer element, so crucial to the novel, is not introduced until later.
tl;dr: Don't infodump. Get your reader invested in a character quickly, and always introduce only the worldbuilding elements that are needed to understand what's going on here and now. If the information doesn't become relevant until later, introduce it later. Introduce elements in a way that's engaging - never make the reader feel they're reading an encyclopedia.
If Tolkien had started The Hobbit or the Lord of the Rings with the Silmarillion, no-one would ever have got to the story. Most people can't stomach the Silmarillion even after they've read the novels.
Similarly with Robert Jordan's Wheel of Time Series.
Robert Jordan is particularly good at dropping hints about what is to come or be revealed. Mysterious objects or people may be encountered from an earlier age that isn't explained until later. This creates a sense of mystery and suspense. Knowledgeable characters may converse about things as yet unknown by listening naive characters. These references are intriguing to them and to the reader.
Other answers are correct that you should skip over exposition of all kinds. They're consistent with answers to other questions on this site. Furthermore, they're consistent with a lot of my own experience as a reader.
But any good writing teacher would promise you that once you understand the rules you're free to break them!
I see three other approaches you could take:
- You could blaze ahead with a whole chapter of 3rd-person-omniscient exposition before your story actually begins. This probably isn't the best idea, but if you clearly label it as a prologue it might work. (or a chorus if you break up the infodump into a few segments throughout the book.)
- You can include an appendix. These can be good fun, and there's lots of ways you can organize them. Several warnings from my own experience:
- Not everyone will read them, so the story needs to make sense without them (or give clear indications about when the reader should look something up; a footnote would work).
- On the other hand people who do read them may be annoyed to reread the same information within the story after spending the time to read the appendix.
- My instinct is always to read a codex straight from front to back. Am I going to want to read your appendix after I finish your story? Is that when you want me to read it?
- You'll probably want to include a table of contents at the beginning; otherwise I won't know to look for an appendix at the end.
- Fabricate one or more epigraphs. These could be just a few lines, in keeping with the modern style, or these could be lengthy Victorian Gothic letters quoted in full. Careful design can help cue readers when they're safe to skip ahead to the action.
"How many pages of setting up a universe is too much given the fact that it is pretty complex and ...?"
YAAAWN. I'm already bored. Zero pages.
Never explain anything. The reader will learn as your characters experience it. If the characters don't experience it, it doesn't need to be told anyway. Here's an infodump that works:
She pushed away from the screenwall to catch her wayward pouch of coffee. "It says here that the war is going badly."
Mike didn't even look up at her. "That's what my son said last time I heard from him."
Now you know a lot, and critically, you want to know more. Who are these people? Where are they? When is it? What sort of story is this? What is their relationship? Who is at war? Why is it going badly? Where is Mike's son?
What is the next line you would write in this example?
You can use the info-dump successfully in at least one situation: if your book is comedy and your setup is hysterically funny. Read the introduction to The Princess Bride. When my friend read it to us on the T as we were heading to the movie when it premiered back in the 1980's, I almost died laughing, and the backstory had almost zero relevance to the story. It merely set the tone. If you are that funny, you can put anything you want in that first chapter.
It is generally not very effective to try an introduce big chunks of exposition, especially near the beginning of a story as it tends to be fairly dry information and gives the reader little incentive to continue reading. The first few chapters are what sets the tone of story and you generally want to start with something which is going to make peopel keep reading and intriguing unanswered questions are much better in this respect than a dense block of information.
As a writer you should be aiming to give the world you create colour and texture and often the best way to do this is from the perspective of interesting characters.
Bear in mind also that if you have an original and complex universe you could write a pretty long book and only scratch the surface. Consider a novel set in the real world, how much actual information about the world do you think it might contain ? Probably not that much.
Equally thorough and detailed world building is good but you don't necessarily need to put it all on paper directly. It can be useful in informing the story without having to be spelled out in detail.
Think about what is relevant to and driving the story and what is relevant and interesting to the characters. It is often better to assume that readers are as familiar with your world as they are the real world.
You also want to be wary of creating needless analogues of familiar things just for the sake of being 'original'. I personally don't want to read half a page of description of f'khargi space brew which turns out to be for all practical purposes tea and is then never mentioned again.
I think a useful test on whether something is an infodump is to put yourself in the position of a character and think about how you would explain something in spoken conversation.
There are a lot of good answers already, but here's another point: a great way to reveal details is conflict. Apart from giving characters a good excuse to remind each other of something they all know, it automatically drives the plot and fleshes out the characters. Let's look at a few examples of this in action, all taken from Disney's Hercules. It's a film that had to explain a lot of Greek myth (albeit their modification of it) to the audience in a short time.
- The film begins with the Muses telling a narrator they'll take over from him because he's too austere. This allows them to introduce their more fun and song-based style of narration.
- There is also conflict between individual Muses - nothing too harsh or verbose, but enough you get a feel for their individual personalities, and how it'll factor into both spoken and sung narration.
- In song they blitz through the Titanomachy to the Olympian era, both revealing a conflict between two groups of gods and setting us up for the film's entire plot.
- As we get accustomed to the unique biological rules on Mount Olympus, Hades comes in and you can feel the tension in the air. He doesn't glow like his fellow immortal gods, which makes his villainy more obvious. But his dialogue with the others quickly slips in his resentment over being forced to reside in the underworld, and how he wishes Zeus could somehow die.
- Next Hades goes to the underworld and we quickly see him rub up against dead souls, his staff and the Fates. Each instance tells you something else about the world. They don't need to pause everything and say, "these are the Fates, who know all and direct all". Instead we get the hilarious "I KNOW you know, I got it, I got the concept" scene, while Hades frustatedly tries to have a normal conversation about - you guessed it - his conflict with Zeus.
- I'll skip a minute or so of plot to where Hades orders Pain and Panic to abduct the infant Hercules, turn him mortal and kill him. Pain and Panic don't have identical views, and the conflict between them tells you a little about their relationship with each other and Hades. And the when/if Hades finds out exchange sets us up for the dénouement, with the matter of when/if Hades gets out of the Styx.
- A minute or so later, we skip to an adolescent Hercules, who is clearly very distrusted in his community, and it doesn't take long to find out why. "Jerkules" accidentally breaks everything, eventually leading the townspeople to turn on him and his human adoptive father Amphitryon. At this point we've already heard from the Muses about Herc's great strength, but now we see what that means in his life. It also drives Amphitryon and his wife Alcmene to reveal his connection to the Olympians, and that sets the next part of the plot in motion.
- Herc has to convince Philoctetes to train him. Phil's having none of it. He's been disappointed before by Achilles, Jason and "a lot of -euses". It takes Zeus striking him with lightning before he's convinced to help.
- Megara's introduction shows her in conflict with several characters in quick succession: the river guardian, Herc, Pain, Panic and Hades. Each exchange reveals different information about him, and sets up dramatic irony (i.e. we know she's working with the villains, but Herc doesn't). It also involves conflict between Hades and his other minions, when he discovers Herc's alive and they've kept it from him until almost the deadline for killing him.
- Herc wants hero work, but the people of Thebes are as disinterested as Phil had been. You quickly learn they've endured many trials, and amateur heroes have mishandled them so often they won't give a newbie a chance. It takes a prolonged and difficult defeat of a Hydra for them to change their minds. The conflict here is not between Herc and the Hydra; it's between him and the townspeople.
Other conflicts occur throughout the film, but I won't mention them because by this point the worldbuilding is complete (save for occasional touches, e.g. when the Titans approach Olympus and Hephaestus arms Zeus, or Hades gloats over Meg's imminent death, and Perseus doesn't reach her before Atropos cuts Meg's thread of life). I want to stress the above is all from memory, not rewatching the film to write this. The reason I can manage all that is because of how well conflict, worldbuilding, plot, characterisation etc. are intertwined throughout.