The popular conventional wisdom seems to be that the defender had a decisive advantage in the First World War, because of machine guns, entrenchment and whatnot. But, looking the casualty statistics of the large battles, the numbers are quite similar for both sides (For example in 1st Marne, Somme, Passchendaele and Kaiserschlacht the casualty figures in Wikipedia show that the attackers took at most around 1.5 times the defenders casulties). That would seem to show that the defender's advantage was not that big. What made their casualties so high? Am I overlooking something critical here?
The defender has the advantage of prepared defences (trenches and barbed wire). But the attackers has advantages, too. Typically, before a major attack, the attacker will accumulate large amounts of artillery ammunition, and will often bring in more guns. The attacker will use reconnaissance to locate enemy artillery positions (and other methods such as sound ranging and flash ranging, as far as possible), and will target those in the initial attack. As a result, the attacker often has a large artillery advantage early in the offensive (which is eroded as the offensive continues, as the defender brings in more ammunition and guns). In an ideal offensive - rarely achieved in practice - the attacker's artillery clears paths through the barbed wire, and kills the defenders in their trenches, so that the attackers only need to occupy the undefended trenches. Once in the trenches, the artillery fires a barrage (in the original and literal sense, a barrier) to stop counter-attacks from recapturing those trenches.
In practice, the defenders take cover in dugouts, leaving a minimal force exposed to the artillery fire in the trenches, and reoccupy the trenches when the infantry attacks. The attacker can counter this by having the infantry attack following as closely as possible behind the artillery (and tricks like stopping the artillery fire so that the defenders reoccupy the trenches expecting the infantry attack, but instead receive renewed artillery fire). And, even if the defenders aren't wiped out by the artillery attack, they can still take many casualties.
Further, the objectives of attacks are often high ground that overlooks the rest of the defences. If the attack succeeds, and the attacks retains control of the captured positions, they are often able to direct effective fire on the rest of the defensive positions. The defender is faced with the prospect of an even worse time in their defensive positions, with more chance of further attacks succeeding. To avoid this, they could abandon their positions and withdraw - forcing this to happen is often one of the major goals of the attacker (better to take key positions and force abandonment of the rest of the defences rather than grind away at the entire defensive position). The defender's other alternative is to counter-attack, to recapture the taken positions. This exposes the counter-attackers to artillery fire - often already firing as a barrage - and to small arms fire from the original attackers occupying the position. To make things worse, such counter-attacks often need to be made with little preparation and less-than-adequate forces. To wait to prepare will give the attackers-turned-defenders time to repair damage to the trenches, place barbed wire, and so on.
So while the attackers take many casualties from artillery, machine guns, and small arms fire as they attack, the defenders take many casualties from the initial artillery attack and in counter-attacks.
Note that artillery was the main killer in combat and the main causer of wounds in the war. While soldiers in the trenches had good protection from small arms fire, they were still vulnerable to artillery (much less vulnerable than if they were in the open, but still vulnerable). If the trenches were too lightly defended, they couldn't be held against an attack. If the defenders remained in well-protected dugouts where they were safe against artillery, they couldn't defend against an infantry attack. Successful defence meant exposing your soldiers to enemy artillery, and that meant casualties.
Expanding a little on what /u/wotan_weevil wrote about the tactical problems faced by defenders, especially respecting artillery, and on what they alluded to about counterattacks; it might be useful to zoom out a bit and explicitly state that many of the "large battles," even though we often think about them as having one attacker and one defender, in reality were weeks- or months-long grinds composed of many sub-battles in which the opposing armies often locally traded roles between attacker and defender.
Popular depictions of WWI battles often tend to overemphasize overrunning the enemy trenches as being the goal that decides victory or defeat, and neglect actions following the first attack; success lies completely with capturing or not capturing the enemy trenches, and either the attack captures the enemy trenches due to this or that special factor, in which case the battle is over and won, or everyone gets cut down before getting there, in which case the whole attack was a hopeless stupidity that should presumably never have been done.
In reality counterattack was a central element of the defensive strategy of every army in defending the trench lines of WWI, and attacks that captured their initial objectives (which attacks pretty often did) typically had to worry about fighting off vigorous counterattacks before they could proceed on to any secondary objectives and exploitation of their gains. Successful counterattacks in turn might prompt fresh waves of attacks by the original attacker to try to reinforce, consolidate, or just retake their initial gains. This seesaw of attack and counterattack is a prominent characteristic of WWI trench warfare.
Counterattacking of course involves the defender exposing himself to many of the same dangers that the attacker did, so it's not that hard to see that it was a risky proposition that could involve the counterattacker suffering serious casualties (and often did when counterattacks went more poorly than hoped). Why do it at all then rather than just staying on the tactical defensive all the time and bleeding the enemy dry each time he attacked, maybe giving ground to the enemy over time, but inflicting horrifically disproportionate casualties because you are always enjoying the huge advantages of defense?
To answer this we can partly say that the tactical advantages of defense, while real, may not have been so extreme and could be set against other advantages the attacker could assemble (see wotan_weevil's post again for some of these); partly because (see his post again), attackers tended to aim at strategically beneficial positions, which if they were allowed to reinforce, consolidate, bring in artillery, etc. might allow them to cause major disarray in the defense rather than just minor adjustments; and partly also, and this is important to understanding why the Western Front stayed so still, because a successful attacker often attacked his way into a position in which, if he weren't allowed to reinforce, consolidate, etc., he could be at his most vulnerable. A unit of soldiers that had just successfully attacked and captured an objective well ahead of their own lines was likely to find itself in a position difficult to supply with ammunition, reinforcements, etc. (because their new trenches were previously the enemy's and won't be connected to their own), difficult to support (because they may have gone out of range of their artillery or at least a lot of their shorter-range artillery pieces), and even difficult to communicate with (because they'd have advanced away from the prelaid landlines of the field telephones, which often meant it was harder and slower to communicate exactly where and when reinforcements, artillery barrages, etc. were needed, even when such would have been available). Not to mention physically and mentally worn out. The opportunity to attack the enemy when he was suffering all these disadvantages could obviously be very attractive to a defending commander, enough to make launching a dangerous counterattack seem like a very worthwhile risk. And often these risks paid off by overrunning the attackers in turn.
This characteristic phenomenon of attacks being rolled back or bogged down after initial success (due to the serious difficulty that armies on all sides faced in consolidating local advances), as opposed to just failing outright at the beginning, was a big reason that the Western Front remained so static, more so than the multilayered trench systems and machine gun nests. Major defensive works like these grew up after the frontlines set, and were to some extent a symptom rather than a cause.
(to some extent... not to say that the elaborate defenses didn't, as they grew, become a self-reinforcing contributor to the stasis, too)
So TLDR, it wasn't possible, nor was it desirable, for the side that was strategically defending in a battle to spend the whole time on the tactical defensive, mowing down waves of attackers with machine guns from the relative safety of the trenches. Attackers had various ways to overcome such defenses, but then in the aftermath of success might present an vulnerable target for attack themselves, causing the defender to bring up reserves and take the opportunity to switch roles. Dealing with the aftermath of an advance and the near-inevitable counterattack presented a huge challenge on the Western Front, a challenge that was bigger and did more to define the course of that theater of war than the challenge of capturing a defended trench.