It depends. Generally, OPT holders have a 60-day grace period after their EAD expires. During this time, they can stay in the US, and they can file an application to change to another immigration status. If on the day your H1B application is filed you are: 1) still in the US, 2) still within your grace period, and 3) your employer requests a change of status for you (as opposed to consular processing), then you can likely stay in the US while your application is pending. If any of these three factors is absent, your pending H1B application will not give you the ability to remain in the US.
If your application is selected in the lottery and your change of status request is approved, congratulations! You can stay in the US until October 1 when your H1B status takes effect. If your application is not selected in the lottery, or is selected but then denied, you would lose your ability to remain in the US based on the H1B application, and would need to leave immediately.
Keep in mind that an H1B change of status application filed during the grace period after OPT expires only gives you permission to physically stay in the US. Unlike cap-gap protection (which only applies if your EAD is still valid on the day your H1B application is filed), it does not extend work authorization, so you must stop working for your employer until October 1 when your H1B is activated.
Please keep in mind this is a general rule only. The specific facts of your case may mean that this general rule will not apply to you. For instance, if you have exceeded the maximum allowed time of unemployment during your OPT, then you will actually not have grace period after your EAD expires. For this reason, it is important to speak with an attorney about your particular case before you determine whether or not you can stay in the US beyond the expiration of your EAD.
If you have general questions on this topic, feel free to leave a comment and I will try to respond. Please note that I cannot respond to questions regarding the specific facts of your case on this blog, but I would be happy to discuss these questions with you over the phone or Skype! You can schedule a consultation here.