The unique characteristics of nanostructures are mainly due to their large surface to volume ratio. One of the most important quantities in investigating the surface properties of materials is the surface energy. Therefore, calculating the surface energy is necessary for the proper understanding of the behavior and properties of nanostructured materials. The present study investigates the size dependent surface energy of crystalline nanoparticles and nanocavities of aluminum, silver, copper and iron in crystalline state and aluminum in amorphous state. For this purpose, spherical nanoparticles and nanocavities with different diameters are modeled by molecular dynamics simulations and their surface energy is obtained. Initially, the molecular dynamics simulation results for the flat surface of a semi-infinite body are verified against the existing data in the literature. The simulation results demonstrate that for nanoparticles and nanocavities with sufficiently small diameters in the range of a few tens of nanometers, the surface energy depends on the size of the nanostructure. For spherical nanoparticles the surface energy increases with increasing nanoparticle diameter, while for the spherical nanocavities the surface energy decreases by increasing nanocavity diameter. Also, the surface energy variation with size is more intense for nanocavities in comparison with nanoparticles. By increasing the diameter, the surface energy of nanoparticles and nanocavities approaches to an asymptotical value which in case of crystalline materials is the surface energy of a crystalline flat surface or the Gi surface energy for the crystallographic surface orientation with the maximum surface energy and in case of amorphous material is the surface energy of semi-infinite body. Keywords: Surface free energy, Nanoparticle, Nanocavity, Metallic glass, Nanostructures