First two pregnancies I told my boss about 7 weeks, as I'd been off with sickness for a few days and didn't want to make up excuses. He kept it quiet and I told the office at large at 12 weeks.
This time, I told one of my bosses quietly the day after I found out, as I was on a company away day and needed to quietly get out of doing white water rafting (I was asked to fill in a medical form which included "are you pregnant?"). He kept it to himself and I "officially" told both my bosses at about 8/9 weeks, then the office in general at 12 weeks.
They have reacted really well every time, and I'm glad I've generally told early as my job won't be covered by maternity cover so my workload will need to be spread around the office, so it seems fair to give them as much time as possible to plan for that.