I like the accepted answer, but had a slightly different spin.
Why do companies ask?
Business means competition. While the competition for opportunities to make money are obvious - there's also a competition for resources. Just like two companies from different fields may bid over the price of a given limited physical resource (like gold, oil, or computer chips) - they bid, very subtly, over the availabilty of key talent.
Particularly in knowledge work - there's a fairly finite number of people with the skills, dedication and intelligence to do the work ably and efficiently - particularly in any given location. The more people you can have on staff to do the work, the better your product, service or other output will be, and the more of it you can generate in a given time period.
So - recruitment and retention of staff isn't just a "nice to have", it's a cornerstone of a successful business.
In other words - no matter how great your product is, if you can't retain enough staff to keep it going, you won't be successful as a business in the long term.
The more a company can learn about its competition for talent, the more it can tailor its employment opportunities to beat out the competition. Often the "win" isn't just the simple numbers - salary, vacation days, value of benefit package - it's subtler things like brand reputation, work opportunities and cultural perks. This stuff isn't easy to figure out from a company's website - the only way you can find this information is to ask, and the best people to ask are the ones who you know are a good fit for this company. And that means exiting employees.
What should you say?
It's really your call. And it's somewhat a question of:
- what's your agreement with the new job? Did they ask for confidentiality?
- how private do you want to be about your new salary and benefits?
- how much do you trust your current management and how much do you want to help them?
- do you have any desire for a counteroffer?
This trumps all. Don't give away business secrets - either from your old company or your new one. That will both burn bridges and get you in legal trouble. And being the guy who's not trustworthy with a secret really isn't ever a reputation win.
Different people will feel differently about this, and the situation will certainly be an influence. Personally, I've been open to sharing this - my general thought is that the current company knows my current salary and benefits, so at least being clear about the general nature of the difference isn't such a crazy thing to share. Particularly when a big reason for leaving is a serious case of underpayment, or a reduction in benefits - it's worth being clear that this was a factor.
How clear you want to be is entirely up to you. I know many people feel uncomfortable about sharing salary specifics - but saying "a substantial increase" or "more than my typical raises in this company" or some other frame of reference can be useful. Particularly if you are talking about an enormous difference, it can be a kindness (if you like your current employers) to be clear that the market rate of their salaries is WAY under the opportunities that are currently available.
There's two aspects - if you work with people you don't trust, then I'd advise against sharing personal information. Why do favors for people you don't trust?
But if you have a good rapport with your management and your company in general, sharing information does two things:
It informs your management about the risks of others leaving. They know the picture of salaries across the company (or some subset of it). If you are underpaid or get too few benefits for the current state of the market for your skill set - it's likely that others are at risk of leaving for the same reason. If management can make a change to pay or benefits, this may give them forewarning to stop the flood of people leaving.
It may just help your coworkers. Many benefits are provided largely for the competition for talent. If enough people leave to get a certain benefit, the company may be inspired to offer it to the remaining workers. This is less likely with big stuff like salaries, but much more doable in smaller companies with things like flexible hours, work at home or other work/life balance bonuses.
There's no magic recipe for a counter offer. The reasons a company may not make an offer are numerous, and it's impossible to predict with any certainty.
One point, though, is that the vaguer you are about why you're leaving, the less certain that your management will be that any counteroffer would do any good. If they ask, clearly and directly - "what would it take to make you stay?" and you say something like "I really can't discuss that" or "It's nothing all that specific, it's just a vague desire to be doing different work" - then they likely won't bother, since there's no way to figure out WHAT would get you to stay.
That said, a super clear and specific answer doesn't guarantee anything... it just ups the chances that if the company WANTS to make a counter offer, they at least have the information necessary to go about putting one together.