Preheat the oven to 350°F (175°C).
Bring a large pot of salted water to a boil and cook the spaghetti according to package directions until al dente. Drain and set aside.
Spoon a light layer of spaghetti sauce over the bottom of a 9×13-inch casserole dish.
Add a layer of cooked spaghetti over the sauce, then sprinkle a light layer of mozzarella and a layer of pepperoni.
Repeat layering (spaghetti, sauce if desired, mozzarella, pepperoni) until the dish is full, finishing with cheese and some pepperoni on top.
Bake in the preheated oven for 20–30 minutes, until heated through and bubbly.
If desired, switch the oven to broil and broil 2–5 minutes until the cheese begins to brown, watching closely to avoid burning the pepperoni.
Blot the top with a paper towel to absorb excess grease from the pepperoni, then serve.