Batteries will last longer if your laptop is used primarily plugged in. A battery's life is generally counted by the amount of recharges. Using on battery, you are constantly discharging and charging the battery, and it will slowly wear out the more charging cycles it goes through.
On the other hand, if you used plugged in, the battery is not constantly going through charging cycles, and will usually last longer than if using the laptop primarily on battery power.
As an example, a laptop used for three years while almost always plugged in, will have longer battery life than the same computer that was only plugged in to recharge the battery.
There are some more technical exceptions and things that can wear a battery down, but this is the general principle.