There's no hard rule, but most women wait until the end of the first trimester (when the risk of miscarriage goes way down). But, you may want to do it sooner or later depending on your relationship with your boss and when you start to show. Better to break the news yourself than let someone else (or your growing belly!) do it for you.
Try to break the news after you’ve completed an assignment—this sends the message that your condition hasn’t impacted your productivity thus far, and that you have every intention of doing your job (and doing it well) for the remainder of your pregnancy. Another smart move: Before you talk, put together a plan outlining how your duties will be covered during your leave. Your boss is much more likely to greet the news with enthusiasm if he or she knows you’ve got the situation covered.