Every time you move your baby away from a sharp table corner or take away a choking hazard, you're showing her what is and isn't safe for her to be around. Your conversation about stranger safety, whether you know it or not, actually started before your baby could even talk. You've always been teaching her that there are some things that are safe to be around and some that aren't.
As your child gets older, the information you give her about safety around strangers can become more complex. At this stage, you just want to help your baby understand what a stranger is (someone we don't know) and why she shouldn't talk to people she doesn't know without you (it's not safe). You can point out people that would be good to talk to if your baby couldn't find you for some reason, like a police officer or a grocery store clerk. And you may find it helpful to teach your baby that people in uniforms are likely to be able to help her if she needs something.
At 2 and 3 years old, your baby is able to understand a lot of things but can't necessarily respond to them. You can point things out, but it will probably be hard to carry a conversation about being safe around strangers. If you see a police officer, you could prompt your baby to wave or say hi, signaling that he's a safe person to talk to. If your baby were to start walking away from you in a store, you could retrieve her and say, "I need you to stay with me. We don't know anyone else here." your baby might not fully understand, but you can start with these small safety tips.
(A note here regarding some of these recommendations: these are just meant to serve as examples, and we recognize that police officers and other uniformed officers may not feel like a safe resource for all people in all communities - most notably for people of color. So you should introduce and point out people who you feel good about being a source of safety and security for your child in a way that makes the most sense for you.)
As your baby gets older, you can ask her questions about hypothetical situations to make sure she knows what to do if a stranger approaches her. "If someone you don't know comes to talk to you, what do you do? If someone seems nice, do you still talk to them? If someone tries to take you somewhere, what do you do?" It can be hard to have that conversation, but it's important that your baby knows that she can scream for help if she doesn't feel safe.
Once your baby is 4 or 5, you can expand on her knowledge about strangers. You can give her a safety word and tell her that any stranger who says they know you will be able to recite the word. You can also explain that even a nice stranger who just says they need help with directions or with a lost animal is still a stranger who she shouldn't talk to. Make sure your baby knows never to accept a ride home from someone who doesn't know the safety word.
You might want to give your baby the same basic rule that your parents might have given you: don't talk to strangers. It can be a hard line to draw because of different circumstances that will require them to talk to new people, but it could be a good piece of advice for your baby to fall back on when she isn't sure what to do.